]> git.ipfire.org Git - people/ms/dma.git/blobdiff - util.c
dns: do not treat unreachable DNS server as permanent error
[people/ms/dma.git] / util.c
diff --git a/util.c b/util.c
index 46619d7ced7432c51c462134f2e50f7ca68323f7..d528f313d091769b17582f8d46704165c10dcaea 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1,8 +1,9 @@
 /*
+ * Copyright (c) 2008-2014, Simon Schubert <2@0x2c.org>.
  * Copyright (c) 2008 The DragonFly Project.  All rights reserved.
  *
  * This code is derived from software contributed to The DragonFly Project
- * by Simon 'corecode' Schubert <corecode@fs.ei.tum.de>.
+ * by Simon Schubert <2@0x2c.org>.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -51,6 +52,9 @@
 const char *
 hostname(void)
 {
+#ifndef HOST_NAME_MAX
+#define HOST_NAME_MAX  255
+#endif
        static char name[HOST_NAME_MAX+1];
        static int initialized = 0;
        char *s;
@@ -115,7 +119,7 @@ local:
 void
 setlogident(const char *fmt, ...)
 {
-       char tag[50];
+       static char tag[50];
 
        snprintf(tag, sizeof(tag), "%s", logident_base);
        if (fmt != NULL) {
@@ -145,6 +149,7 @@ errlog(int exitcode, const char *fmt, ...)
                va_end(ap);
        }
 
+       errno = oerrno;
        if (*outs != 0) {
                syslog(LOG_ERR, "%s: %m", outs);
                fprintf(stderr, "%s: %s: %s\n", getprogname(), outs, strerror(oerrno));
@@ -198,21 +203,20 @@ void
 set_username(void)
 {
        struct passwd *pwd;
-       uid_t uid;
 
-       uid = getuid();
-       if (check_username(getlogin(), uid))
+       useruid = getuid();
+       if (check_username(getlogin(), useruid))
                return;
-       if (check_username(getenv("LOGNAME"), uid))
+       if (check_username(getenv("LOGNAME"), useruid))
                return;
-       if (check_username(getenv("USER"), uid))
+       if (check_username(getenv("USER"), useruid))
                return;
-       pwd = getpwuid(uid);
+       pwd = getpwuid(useruid);
        if (pwd != NULL && pwd->pw_name != NULL && pwd->pw_name[0] != '\0') {
-               if (check_username(pwd->pw_name, uid))
+               if (check_username(pwd->pw_name, useruid))
                        return;
        }
-       snprintf(username, sizeof(username), "uid=%ld", (long)uid);
+       snprintf(username, sizeof(username), "uid=%ld", (long)useruid);
 }
 
 void