chiark / gitweb /
build-sys: initial support ALTLinux
[elogind.git] / src / util.c
index 0cd78f6561e9b03633e9b97567d0b38e6c31eb0e..7692a2d620cbe5464ddfe1c74d23796e154fc707 100644 (file)
@@ -250,7 +250,7 @@ int parse_boolean(const char *v) {
 }
 
 int parse_pid(const char *s, pid_t* ret_pid) {
-        unsigned long ul;
+        unsigned long ul = 0;
         pid_t pid;
         int r;
 
@@ -2617,33 +2617,6 @@ int make_null_stdio(void) {
         return make_stdio(null_fd);
 }
 
-bool is_clean_exit(int code, int status) {
-
-        if (code == CLD_EXITED)
-                return status == 0;
-
-        /* If a daemon does not implement handlers for some of the
-         * signals that's not considered an unclean shutdown */
-        if (code == CLD_KILLED)
-                return
-                        status == SIGHUP ||
-                        status == SIGINT ||
-                        status == SIGTERM ||
-                        status == SIGPIPE;
-
-        return false;
-}
-
-bool is_clean_exit_lsb(int code, int status) {
-
-        if (is_clean_exit(code, status))
-                return true;
-
-        return
-                code == CLD_EXITED &&
-                (status == EXIT_NOTINSTALLED || status == EXIT_NOTCONFIGURED);
-}
-
 bool is_device_path(const char *path) {
 
         /* Returns true on paths that refer to a device, either in
@@ -3044,17 +3017,40 @@ void status_welcome(void) {
         if (!ansi_color)
                 const_color = "1;34"; /* Light Blue for Gentoo */
 
-#elif defined(TARGET_DEBIAN)
+#elif defined(TARGET_ALTLINUX)
 
         if (!pretty_name) {
-                if ((r = read_one_line_file("/etc/debian_version", &pretty_name)) < 0) {
+                if ((r = read_one_line_file("/etc/altlinux-release", &pretty_name)) < 0) {
 
                         if (r != -ENOENT)
-                                log_warning("Failed to read /etc/debian_version: %s", strerror(-r));
+                                log_warning("Failed to read /etc/altlinux-release: %s", strerror(-r));
                 } else
                         truncate_nl(pretty_name);
         }
 
+        if (!ansi_color)
+                const_color = "0;36"; /* Cyan for ALTLinux */
+
+
+#elif defined(TARGET_DEBIAN)
+
+        if (!pretty_name) {
+                char *version;
+
+                if ((r = read_one_line_file("/etc/debian_version", &version)) < 0) {
+
+                        if (r != -ENOENT)
+                                log_warning("Failed to read /etc/debian_version: %s", strerror(-r));
+                } else {
+                        truncate_nl(version);
+                        pretty_name = strappend("Debian ", version);
+                        free(version);
+
+                        if (!pretty_name)
+                                log_warning("Failed to allocate Debian version string.");
+                }
+        }
+
         if (!ansi_color)
                 const_color = "1;31"; /* Light Red for Debian */
 
@@ -3071,13 +3067,6 @@ void status_welcome(void) {
         if (!ansi_color)
                 const_color = "0;33"; /* Orange/Brown for Ubuntu */
 
-#elif defined(TARGET_ARCH)
-
-        if (!pretty_name)
-                const_pretty = "Arch Linux";
-
-        if (!ansi_color)
-                const_color = "1;36"; /* Cyan for Arch */
 #endif
 
         if (!pretty_name && !const_pretty)
@@ -3089,6 +3078,9 @@ void status_welcome(void) {
         status_printf("Welcome to \x1B[%sm%s\x1B[0m!\n",
                       const_color ? const_color : ansi_color,
                       const_pretty ? const_pretty : pretty_name);
+
+        free(ansi_color);
+        free(pretty_name);
 }
 
 char *replace_env(const char *format, char **env) {
@@ -3325,6 +3317,44 @@ char *unquote(const char *s, const char* quotes) {
         return strdup(s);
 }
 
+char *normalize_env_assignment(const char *s) {
+        char *name, *value, *p, *r;
+
+        p = strchr(s, '=');
+
+        if (!p) {
+                if (!(r = strdup(s)))
+                        return NULL;
+
+                return strstrip(r);
+        }
+
+        if (!(name = strndup(s, p - s)))
+                return NULL;
+
+        if (!(p = strdup(p+1))) {
+                free(name);
+                return NULL;
+        }
+
+        value = unquote(strstrip(p), QUOTES);
+        free(p);
+
+        if (!value) {
+                free(p);
+                free(name);
+                return NULL;
+        }
+
+        if (asprintf(&r, "%s=%s", name, value) < 0)
+                r = NULL;
+
+        free(value);
+        free(name);
+
+        return r;
+}
+
 int wait_for_terminate(pid_t pid, siginfo_t *status) {
         assert(pid >= 1);
         assert(status);
@@ -3378,6 +3408,8 @@ int wait_for_terminate_and_warn(const char *name, pid_t pid) {
 }
 
 void freeze(void) {
+        sync();
+
         for (;;)
                 pause();
 }
@@ -3394,8 +3426,19 @@ bool null_or_empty(struct stat *st) {
         return false;
 }
 
-DIR *xopendirat(int fd, const char *name) {
-        return fdopendir(openat(fd, name, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC));
+DIR *xopendirat(int fd, const char *name, int flags) {
+        int nfd;
+        DIR *d;
+
+        if ((nfd = openat(fd, name, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|flags)) < 0)
+                return NULL;
+
+        if (!(d = fdopendir(nfd))) {
+                close_nointr_nofail(nfd);
+                return NULL;
+        }
+
+        return d;
 }
 
 int signal_from_string_try_harder(const char *s) {
@@ -3476,7 +3519,7 @@ char *fstab_node_to_udev_node(const char *p) {
                 if (!t)
                         return NULL;
 
-                r = asprintf(&dn, "/dev/disk/by-uuid/%s", ascii_strlower(t));
+                r = asprintf(&dn, "/dev/disk/by-uuid/%s", t);
                 free(t);
 
                 if (r < 0)
@@ -3518,7 +3561,7 @@ const char *default_term_for_tty(const char *tty) {
 
         /* FIXME: Proper handling of /dev/console would be cool */
 
-        return "TERM=vt100-nav";
+        return "TERM=vt100";
 }
 
 static const char *const ioprio_class_table[] = {