From 9d709a294b81066a0942a7a642df1b3d4940ad26 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 31 Aug 2006 18:32:27 +0000 Subject: avahi_set_proc_title(): change the process name with prctl() if available git-svn-id: file:///home/lennart/svn/public/avahi/trunk@1300 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- avahi-daemon/chroot.c | 2 +- avahi-daemon/main.c | 8 ++++---- avahi-daemon/setproctitle.c | 13 ++++++++++++- avahi-daemon/setproctitle.h | 4 +++- 4 files changed, 20 insertions(+), 7 deletions(-) (limited to 'avahi-daemon') diff --git a/avahi-daemon/chroot.c b/avahi-daemon/chroot.c index 5ca605d..99f52fa 100644 --- a/avahi-daemon/chroot.c +++ b/avahi-daemon/chroot.c @@ -314,7 +314,7 @@ int avahi_chroot_helper_start(const char *argv0) { /* Drop all remaining capabilities */ avahi_caps_drop_all(); - avahi_set_proc_title("%s: chroot helper process", argv0); + avahi_set_proc_title(argv0, "%s: chroot helper process", argv0); close(sock[0]); helper_main(sock[1]); diff --git a/avahi-daemon/main.c b/avahi-daemon/main.c index b230ff7..6d8abb1 100644 --- a/avahi-daemon/main.c +++ b/avahi-daemon/main.c @@ -267,7 +267,7 @@ static void server_callback(AvahiServer *s, AvahiServerState state, void *userda case AVAHI_SERVER_RUNNING: avahi_log_info("Server startup complete. Host name is %s. Local service cookie is %u.", avahi_server_get_host_name_fqdn(s), avahi_server_get_local_service_cookie(s)); - avahi_set_proc_title("%s: running [%s]", argv0, avahi_server_get_host_name_fqdn(s)); + avahi_set_proc_title(argv0, "%s: running [%s]", argv0, avahi_server_get_host_name_fqdn(s)); static_service_add_to_server(); static_hosts_add_to_server(); @@ -286,7 +286,7 @@ static void server_callback(AvahiServer *s, AvahiServerState state, void *userda case AVAHI_SERVER_COLLISION: { char *n; - avahi_set_proc_title("%s: collision", argv0); + avahi_set_proc_title(argv0, "%s: collision", argv0); static_service_remove_from_server(); static_hosts_remove_from_server(); @@ -308,7 +308,7 @@ static void server_callback(AvahiServer *s, AvahiServerState state, void *userda case AVAHI_SERVER_REGISTERING: - avahi_set_proc_title("%s: registering [%s]", argv0, avahi_server_get_host_name_fqdn(s)); + avahi_set_proc_title(argv0, "%s: registering [%s]", argv0, avahi_server_get_host_name_fqdn(s)); static_service_remove_from_server(); static_hosts_remove_from_server(); @@ -1193,7 +1193,7 @@ int main(int argc, char *argv[]) { #endif avahi_log_info("%s "PACKAGE_VERSION" starting up.", argv0); - avahi_set_proc_title("%s: starting up", argv0); + avahi_set_proc_title(argv0, "%s: starting up", argv0); if (run_server(&config) == 0) r = 0; diff --git a/avahi-daemon/setproctitle.c b/avahi-daemon/setproctitle.c index f8d3ddb..09b7f65 100644 --- a/avahi-daemon/setproctitle.c +++ b/avahi-daemon/setproctitle.c @@ -29,6 +29,10 @@ #include #include +#ifdef HAVE_SYS_PRCTL_H +#include +#endif + #include #include "setproctitle.h" @@ -73,7 +77,7 @@ void avahi_init_proc_title(int argc, char **argv) { #endif } -void avahi_set_proc_title(const char *fmt,...) { +void avahi_set_proc_title(const char *name, const char *fmt,...) { #ifdef HAVE_SETPROCTITLE char t[256]; @@ -99,4 +103,11 @@ void avahi_set_proc_title(const char *fmt,...) { memset(argv_buffer[0] + l, 0, argv_size - l); argv_buffer[1] = NULL; #endif + +#if defined(HAVE_SYS_PRCTL_H) && defined(PR_SET_NAME) + + if (name) + prctl(PR_SET_NAME, (unsigned long) name, 0, 0, 0); + +#endif } diff --git a/avahi-daemon/setproctitle.h b/avahi-daemon/setproctitle.h index 6ac7612..a8f2a1a 100644 --- a/avahi-daemon/setproctitle.h +++ b/avahi-daemon/setproctitle.h @@ -22,7 +22,9 @@ USA. ***/ +#include + void avahi_init_proc_title(int argc, char **argv); -void avahi_set_proc_title(const char *fmt, ...); +void avahi_set_proc_title(const char *name, const char *fmt, ...) AVAHI_GCC_PRINTF_ATTR23; #endif -- cgit