Путеводитель по Руководству Linux

  User  |  Syst  |  Libr  |  Device  |  Files  |  Other  |  Admin  |  Head  |



   sd_pid_notifyf    ( 3 )

уведомлять сервисного менеджера о завершении запуска и других изменениях статуса сервиса (notify service manager about start-up completion and other service status changes)

  Name  |  Synopsis  |  Description  |  Return value  |  Note  |  Environment  |    Examples    |  See also  |

Примеры (Examples)

Example 1. Start-up Notification

When a service finished starting up, it might issue the following call to notify the service manager:

sd_notify(0, "READY=1");

Example 2. Extended Start-up Notification

A service could send the following after completing initialization:

sd_notifyf(0, "READY=1\n" "STATUS=Processing requests...\n" "MAINPID=%lu", (unsigned long) getpid());

Example 3. Error Cause Notification

A service could send the following shortly before exiting, on failure:

sd_notifyf(0, "STATUS=Failed to start up: %s\n" "ERRNO=%i", strerror(errno), errno);

Example 4. Store a File Descriptor in the Service Manager

To store an open file descriptor in the service manager, in order to continue operation after a service restart without losing state, use "FDSTORE=1":

sd_pid_notify_with_fds(0, 0, "FDSTORE=1\nFDNAME=foobar", &fd, 1);

Example 5. Eliminating race conditions

When the client sending the notifications is not spawned by the service manager, it may exit too quickly and the service manager may fail to attribute them correctly to the unit. To prevent such races, use sd_notify_barrier() to synchronize against reception of all notifications sent before this call is made.

sd_notify(0, "READY=1"); /* set timeout to 5 seconds */ sd_notify_barrier(0, 5 * 1000000);