* 3. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by Paul Mackerras
- * <paulus@samba.org>".
+ * <paulus@ozlabs.org>".
*
* THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
#include <sys/mkdev.h>
#endif
-#include "pppd.h"
+#include "pppd-private.h"
#include "fsm.h"
#include "lcp.h"
#include "pathnames.h"
extern char *strerror();
#endif
-static void logit(int, char *, va_list);
+static void logit(int, const char *, va_list);
static void log_write(int, char *);
static void vslp_printer(void *, char *, ...);
static void format_packet(u_char *, int, printer_func, void *);
* Returns the number of chars put into buf.
*/
int
-slprintf(char *buf, int buflen, char *fmt, ...)
+slprintf(char *buf, int buflen, const char *fmt, ...)
{
va_list args;
int n;
#define OUTCHAR(c) (buflen > 0? (--buflen, *buf++ = (c)): 0)
int
-vslprintf(char *buf, int buflen, char *fmt, va_list args)
+vslprintf(char *buf, int buflen, const char *fmt, va_list args)
{
int c, i, n;
int width, prec, fillch;
int base, len, neg, quoted;
long lval = 0;
unsigned long val = 0;
- char *str, *f, *buf0;
+ char *str, *buf0;
+ const char *f;
unsigned char *p;
char num[32];
time_t t;
* logit - does the hard work for fatal et al.
*/
static void
-logit(int level, char *fmt, va_list args)
+logit(int level, const char *fmt, va_list args)
{
char buf[1024];
* fatal - log an error message and die horribly.
*/
void
-fatal(char *fmt, ...)
+fatal(const char *fmt, ...)
{
va_list pvar;
* error - log an error message.
*/
void
-error(char *fmt, ...)
+error(const char *fmt, ...)
{
va_list pvar;
* warn - log a warning message.
*/
void
-warn(char *fmt, ...)
+warn(const char *fmt, ...)
{
va_list pvar;
* notice - log a notice-level message.
*/
void
-notice(char *fmt, ...)
+notice(const char *fmt, ...)
{
va_list pvar;
* info - log an informational message.
*/
void
-info(char *fmt, ...)
+info(const char *fmt, ...)
{
va_list pvar;
* dbglog - log a debug message.
*/
void
-dbglog(char *fmt, ...)
+dbglog(const char *fmt, ...)
{
va_list pvar;
for (done = 0; done < count; ) {
nb = read(fd, ptr, count - done);
if (nb < 0) {
- if (errno == EINTR && !got_sigterm)
+ if (errno == EINTR && !ppp_signaled(SIGTERM))
continue;
return -1;
}
}
#endif
+/*
+ * mkdir_check - helper for mkdir_recursive, creates a directory
+ * but do not error on EEXIST if and only if entry is a directory
+ * The caller must check for errno == ENOENT if appropriate.
+ */
+static int
+mkdir_check(const char *path)
+{
+ struct stat statbuf;
+
+ if (mkdir(path, 0755) >= 0)
+ return 0;
+
+ if (errno == EEXIST) {
+ if (stat(path, &statbuf) < 0)
+ /* got raced? */
+ return -1;
+
+ if ((statbuf.st_mode & S_IFMT) == S_IFDIR)
+ return 0;
+
+ /* already exists but not a dir, treat as failure */
+ errno = EEXIST;
+ return -1;
+ }
+
+ return -1;
+}
+
+/*
+ * mkdir_parent - helper for mkdir_recursive, modifies the string in place
+ * Assumes mkdir(path) already failed, so it first creates the parent then
+ * full path again.
+ */
+static int
+mkdir_parent(char *path)
+{
+ char *slash;
+ int rc;
+
+ slash = strrchr(path, '/');
+ if (!slash)
+ return -1;
+
+ *slash = 0;
+ if (mkdir_check(path) < 0) {
+ if (errno != ENOENT) {
+ *slash = '/';
+ return -1;
+ }
+ if (mkdir_parent(path) < 0) {
+ *slash = '/';
+ return -1;
+ }
+ }
+ *slash = '/';
+
+ return mkdir_check(path);
+}
+
+/*
+ * mkdir_recursive - recursively create directory if it didn't exist
+ */
+int
+mkdir_recursive(const char *path)
+{
+ char *copy;
+ int rc;
+
+ // optimistically try on full path first to avoid allocation
+ if (mkdir_check(path) == 0)
+ return 0;
+
+ copy = strdup(path);
+ if (!copy)
+ return -1;
+
+ rc = mkdir_parent(copy);
+ free(copy);
+ return rc;
+}
+
/* Procedures for locking the serial device using a lock file. */
static char lock_file[MAXPATHLEN];