chiark / gitweb /
fix exit code of udevinitsend and udevmonitor
[elogind.git] / udevinitsend.c
index 26ae5c84185b5a18c74793909427d5229961a624..ea05734a0076fc7871d18af71c9259ad09c722b4 100644 (file)
@@ -1,9 +1,9 @@
 /*
  * udevinitsend.c
  *
- * Userspace devfs
- *
- * Copyright (C) 2004, 2005 Hannes Reinecke <hare@suse.de>
+ * Copyright (C) 2004, 2005 SuSE Linux Products GmbH
+ * Author:
+ *     Hannes Reinecke <hare@suse.de>
  *
  *     This program is free software; you can redistribute it and/or modify it
  *     under the terms of the GNU General Public License as published by the
@@ -128,15 +128,14 @@ static int udevsend(char *filename, int sock, int disable_loop_detection)
                }
 
                if (ch < le) {
-
                        strncpy(&usend_msg.envbuf[bufpos],ls,(ch - ls) + 1);
                        bufpos += (ch - ls) + 1;
                        if (ch[1] == '\'' && le[-1] == '\'') {
-                               strncpy(&usend_msg.envbuf[bufpos],ch + 2, (le - ch) -3);
+                               strncpy(&usend_msg.envbuf[bufpos],ch + 2, (le - ch) - 3);
                                bufpos += (le - ch) - 3;
                        } else {
-                               strncpy(&usend_msg.envbuf[bufpos],ch, (le - ch));
-                               bufpos += (le - ch);
+                               strncpy(&usend_msg.envbuf[bufpos],ch + 1, (le - ch) - 1);
+                               bufpos += (le - ch) - 1;
                        }
                        bufpos++;
                }
@@ -153,9 +152,10 @@ loop_end:
                retval = sendto(sock, &usend_msg, usend_msg_len, 0, (struct sockaddr *)&saddr, addrlen);
                if (retval < 0) {
                        dbg("error sending message (%s)", strerror(errno));
+                       retval = -1;
                }
        }
-               
+
        return retval;
 }
 
@@ -167,7 +167,7 @@ int main(int argc, char *argv[], char *envp[])
        char *event_file = NULL;
        DIR *dirstream;
        struct dirent *direntry;
-       int retval = 1;
+       int retval = 0;
        int disable_loop_detection = 0;
        int sock;
        const char *env;
@@ -218,7 +218,7 @@ int main(int argc, char *argv[], char *envp[])
                if (!dirstream) {
                        info("error opening directory %s: %s\n",
                             event_dir, strerror(errno));
-                       return 1;
+                       return 2;
                }
                chdir(event_dir);
                while ((direntry = readdir(dirstream)) != NULL) {
@@ -235,5 +235,7 @@ int main(int argc, char *argv[], char *envp[])
        if (sock != -1)
                close(sock);
 
-       return retval;
+       if (retval)
+               return 3;
+       return 0;
 }