Message ID | 20180319133321.2140-1-christian.storm@siemens.com |
---|---|
State | Changes Requested |
Headers | show |
Series | notifier: don't initialize socket strucures twice | expand |
Hi Christian, On 19/03/2018 14:33, Christian Storm wrote: > struct sockaddr_un notify_server is initialized via addr_init() > at notify_init()'s start and on initialization in notifier_thread(). > As once is sufficient, remove the initialization in notifier_thread(). > > Signed-off-by: Christian Storm <christian.storm@siemens.com> > --- > core/notifier.c | 15 +++++---------- > 1 file changed, 5 insertions(+), 10 deletions(-) > > diff --git a/core/notifier.c b/core/notifier.c > index f60eb64..f881abf 100644 > --- a/core/notifier.c > +++ b/core/notifier.c > @@ -208,10 +208,13 @@ static void process_notifier (RECOVERY_STATUS status, int event, int level, cons > */ > static void addr_init(struct sockaddr_un *addr, const char *path) > { > - memset(addr, 0, sizeof(struct sockaddr_un)); > + bzero(addr, sizeof(struct sockaddr_un)); bzero is deprecated, memset should be used. > addr->sun_family = AF_UNIX; > + /* > + * Use Linux-specific abstract sockets for this internal interface > + */ > strcpy(&addr->sun_path[1], path); > - addr->sun_path[0] = 0; > + addr->sun_path[0] = '\0'; > } > > /* > @@ -232,14 +235,6 @@ static void *notifier_thread (void __attribute__ ((__unused__)) *data) > fprintf(stderr, "Error creating notifier daemon, exiting."); > exit(2); > } > - memset(¬ify_server, 0, sizeof(notify_server)); > - notify_server.sun_family = AF_UNIX; > - strcpy(notify_server.sun_path, "#NotifyServer"); > - > - /* > - * Use Abstract Socket Address because this is an internal interface > - */ > - notify_server.sun_path[0] = 0; Yes, it is duplicated, thanks for it. > > if (bind(serverfd, (const struct sockaddr *) ¬ify_server, > sizeof(struct sockaddr_un)) < 0) { > Best regards, Stefano
Hi Stefano, > On 19/03/2018 14:33, Christian Storm wrote: > > struct sockaddr_un notify_server is initialized via addr_init() > > at notify_init()'s start and on initialization in notifier_thread(). > > As once is sufficient, remove the initialization in notifier_thread(). > > > > Signed-off-by: Christian Storm <christian.storm@siemens.com> > > --- > > core/notifier.c | 15 +++++---------- > > 1 file changed, 5 insertions(+), 10 deletions(-) > > > > diff --git a/core/notifier.c b/core/notifier.c > > index f60eb64..f881abf 100644 > > --- a/core/notifier.c > > +++ b/core/notifier.c > > @@ -208,10 +208,13 @@ static void process_notifier (RECOVERY_STATUS status, int event, int level, cons > > */ > > static void addr_init(struct sockaddr_un *addr, const char *path) > > { > > - memset(addr, 0, sizeof(struct sockaddr_un)); > > + bzero(addr, sizeof(struct sockaddr_un)); > > bzero is deprecated, memset should be used. Yes, thanks for spotting, was muscle memory :) I sent a v2... Besten Gruß, Christian
diff --git a/core/notifier.c b/core/notifier.c index f60eb64..f881abf 100644 --- a/core/notifier.c +++ b/core/notifier.c @@ -208,10 +208,13 @@ static void process_notifier (RECOVERY_STATUS status, int event, int level, cons */ static void addr_init(struct sockaddr_un *addr, const char *path) { - memset(addr, 0, sizeof(struct sockaddr_un)); + bzero(addr, sizeof(struct sockaddr_un)); addr->sun_family = AF_UNIX; + /* + * Use Linux-specific abstract sockets for this internal interface + */ strcpy(&addr->sun_path[1], path); - addr->sun_path[0] = 0; + addr->sun_path[0] = '\0'; } /* @@ -232,14 +235,6 @@ static void *notifier_thread (void __attribute__ ((__unused__)) *data) fprintf(stderr, "Error creating notifier daemon, exiting."); exit(2); } - memset(¬ify_server, 0, sizeof(notify_server)); - notify_server.sun_family = AF_UNIX; - strcpy(notify_server.sun_path, "#NotifyServer"); - - /* - * Use Abstract Socket Address because this is an internal interface - */ - notify_server.sun_path[0] = 0; if (bind(serverfd, (const struct sockaddr *) ¬ify_server, sizeof(struct sockaddr_un)) < 0) {
struct sockaddr_un notify_server is initialized via addr_init() at notify_init()'s start and on initialization in notifier_thread(). As once is sufficient, remove the initialization in notifier_thread(). Signed-off-by: Christian Storm <christian.storm@siemens.com> --- core/notifier.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)