]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/utils.c
maxfail option, exit code for when when we fail to auth
[ppp.git] / pppd / utils.c
index bec5f89158c8bb6f265e5208b444d8e661cfc612..131429d59a7081f3efb5e5daaeaed036d3a3b025 100644 (file)
@@ -17,7 +17,7 @@
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 #ifndef lint
-static char rcsid[] = "$Id: utils.c,v 1.1 1999/04/12 06:24:53 paulus Exp $";
+static char rcsid[] = "$Id: utils.c,v 1.6 1999/06/24 00:17:48 paulus Exp $";
 #endif
 
 #include <stdio.h>
@@ -40,9 +40,16 @@ static char rcsid[] = "$Id: utils.c,v 1.1 1999/04/12 06:24:53 paulus Exp $";
 #include <sys/stat.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
+#ifdef SVR4
+#include <sys/mkdev.h>
+#endif
 
 #include "pppd.h"
 
+#if defined(SUNOS4)
+extern char *strerror();
+#endif
+
 static void pr_log __P((void *, char *, ...));
 static void logit __P((int, char *, va_list));
 static void vslp_printer __P((void *, char *, ...));
@@ -164,7 +171,8 @@ vslprintf(buf, buflen, fmt, args)
        if (*fmt == 0)
            break;
        c = *++fmt;
-       width = prec = 0;
+       width = 0;
+       prec = -1;
        fillch = ' ';
        if (c == '0') {
            fillch = '0';
@@ -185,6 +193,7 @@ vslprintf(buf, buflen, fmt, args)
                prec = va_arg(args, int);
                c = *++fmt;
            } else {
+               prec = 0;
                while (isdigit(c)) {
                    prec = prec * 10 + c - '0';
                    c = *++fmt;
@@ -258,11 +267,11 @@ vslprintf(buf, buflen, fmt, args)
        case 'q':               /* quoted string */
            quoted = c == 'q';
            p = va_arg(args, unsigned char *);
-           if (fillch == '0' && prec > 0) {
+           if (fillch == '0' && prec >= 0) {
                n = prec;
            } else {
                n = strlen((char *)p);
-               if (prec > 0 && prec < n)
+               if (prec >= 0 && n > prec)
                    n = prec;
            }
            while (n > 0 && buflen > 0) {
@@ -347,7 +356,7 @@ vslprintf(buf, buflen, fmt, args)
            len = num + sizeof(num) - 1 - str;
        } else {
            len = strlen(str);
-           if (prec > 0 && len > prec)
+           if (prec >= 0 && len > prec)
                len = prec;
        }
        if (width > 0) {
@@ -698,7 +707,8 @@ static char lock_file[MAXPATHLEN];
  * lock - create a lock file for the named device
  */
 int
-lock(char *dev)
+lock(dev)
+    char *dev;
 {
 #ifdef LOCKLIB
     int result;
@@ -773,7 +783,9 @@ lock(char *dev)
        lock_buffer[n] = 0;
        pid = atoi(lock_buffer);
 #endif /* LOCK_BINARY */
-       if (pid == 0 || pid == getpid()
+       if (pid == getpid())
+           return 1;           /* somebody else locked it for us */
+       if (pid == 0
            || (kill(pid, 0) == -1 && errno == ESRCH)) {
            if (unlink (lock_file) == 0) {
                notice("Removed stale lock on %s (pid %d)", dev, pid);
@@ -813,7 +825,8 @@ lock(char *dev)
  * between when the parent died and the child rewrote the lockfile).
  */
 int
-relock(int pid)
+relock(pid)
+    int pid;
 {
 #ifdef LOCKLIB
     /* XXX is there a way to do this? */