1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-23 21:35:11 +03:00

fix exit code of udevinitsend and udevmonitor

Thanks to: Marco d'Itri <md@Linux.IT> for the initial patch.

Signed-off-by: Kay Sievers <kay.sievers@suse.de>
This commit is contained in:
Kay Sievers 2005-08-22 12:01:55 +02:00
parent 66691c6e6c
commit 9bbcdb56d8
2 changed files with 15 additions and 8 deletions

View File

@ -128,7 +128,6 @@ static int udevsend(char *filename, int sock, int disable_loop_detection)
} }
if (ch < le) { if (ch < le) {
strncpy(&usend_msg.envbuf[bufpos],ls,(ch - ls) + 1); strncpy(&usend_msg.envbuf[bufpos],ls,(ch - ls) + 1);
bufpos += (ch - ls) + 1; bufpos += (ch - ls) + 1;
if (ch[1] == '\'' && le[-1] == '\'') { if (ch[1] == '\'' && le[-1] == '\'') {
@ -153,9 +152,10 @@ loop_end:
retval = sendto(sock, &usend_msg, usend_msg_len, 0, (struct sockaddr *)&saddr, addrlen); retval = sendto(sock, &usend_msg, usend_msg_len, 0, (struct sockaddr *)&saddr, addrlen);
if (retval < 0) { if (retval < 0) {
dbg("error sending message (%s)", strerror(errno)); dbg("error sending message (%s)", strerror(errno));
retval = -1;
} }
} }
return retval; return retval;
} }
@ -167,7 +167,7 @@ int main(int argc, char *argv[], char *envp[])
char *event_file = NULL; char *event_file = NULL;
DIR *dirstream; DIR *dirstream;
struct dirent *direntry; struct dirent *direntry;
int retval = 1; int retval = 0;
int disable_loop_detection = 0; int disable_loop_detection = 0;
int sock; int sock;
const char *env; const char *env;
@ -218,7 +218,7 @@ int main(int argc, char *argv[], char *envp[])
if (!dirstream) { if (!dirstream) {
info("error opening directory %s: %s\n", info("error opening directory %s: %s\n",
event_dir, strerror(errno)); event_dir, strerror(errno));
return 1; return 2;
} }
chdir(event_dir); chdir(event_dir);
while ((direntry = readdir(dirstream)) != NULL) { while ((direntry = readdir(dirstream)) != NULL) {
@ -235,5 +235,7 @@ int main(int argc, char *argv[], char *envp[])
if (sock != -1) if (sock != -1)
close(sock); close(sock);
return retval; if (retval)
return 3;
return 0;
} }

View File

@ -63,6 +63,7 @@ static int init_udev_monitor_socket(void)
if (retval < 0) { if (retval < 0) {
fprintf(stderr, "bind failed, %s\n", strerror(errno)); fprintf(stderr, "bind failed, %s\n", strerror(errno));
close(udev_monitor_sock); close(udev_monitor_sock);
udev_monitor_sock = -1;
return -1; return -1;
} }
@ -125,13 +126,15 @@ int main(int argc, char *argv[])
if (getuid() != 0) { if (getuid() != 0) {
fprintf(stderr, "need to be root, exit\n\n"); fprintf(stderr, "need to be root, exit\n\n");
exit(1); exit(2);
} }
retval = init_udev_monitor_socket(); retval = init_udev_monitor_socket();
if (retval) if (retval)
goto out; goto out;
init_uevent_netlink_sock(); retval = init_uevent_netlink_sock();
if (retval)
goto out;
printf("udevmonitor prints the received event from the kernel [UEVENT]\n" printf("udevmonitor prints the received event from the kernel [UEVENT]\n"
"and the event which udev sends out after rule processing [UDEV]\n\n"); "and the event which udev sends out after rule processing [UDEV]\n\n");
@ -204,5 +207,7 @@ out:
if (udev_monitor_sock > 0) if (udev_monitor_sock > 0)
close(udev_monitor_sock); close(udev_monitor_sock);
return retval; if (retval)
return 3;
return 0;
} }