Skip to content

Commit

Permalink
Started porting ssh-keygen
Browse files Browse the repository at this point in the history
  • Loading branch information
N-Holzschuch committed Apr 9, 2021
1 parent b787325 commit f0cb2f4
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 75 deletions.
18 changes: 13 additions & 5 deletions ssh_keygen/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@
#endif

#include "log.h"
#include <TargetConditionals.h>
#if TARGET_OS_IPHONE
#include "ios_error.h"
#endif

static LogLevel log_level = SYSLOG_LEVEL_INFO;
static int log_on_stderr = 1;
Expand Down Expand Up @@ -175,7 +178,7 @@ sigdie(const char *fmt,...)
do_log(SYSLOG_LEVEL_FATAL, fmt, args);
va_end(args);
#endif
_exit(1);
cleanup_exit(1);
}

/* void
Expand Down Expand Up @@ -273,7 +276,7 @@ log_init(char *av0, LogLevel level, SyslogFacility facility, int on_stderr)
default:
fprintf(thread_stderr, "Unrecognized internal syslog level code %d\n",
(int) level);
exit(1);
cleanup_exit(1);
}

log_handler = NULL;
Expand Down Expand Up @@ -328,7 +331,7 @@ log_init(char *av0, LogLevel level, SyslogFacility facility, int on_stderr)
fprintf(thread_stderr,
"Unrecognized internal syslog facility code %d\n",
(int) facility);
exit(1);
cleanup_exit(1);
}

/*
Expand Down Expand Up @@ -369,7 +372,7 @@ log_redirect_stderr_to(const char *logfile)
if ((fd = open(logfile, O_WRONLY|O_CREAT|O_APPEND, 0600)) == -1) {
fprintf(thread_stderr, "Couldn't open logfile %s: %s\n", logfile,
strerror(errno));
exit(1);
cleanup_exit(1);
}
log_stderr_fd = fd;
}
Expand Down Expand Up @@ -469,9 +472,14 @@ do_log(LogLevel level, const char *fmt, va_list args)
syslog_r(pri, &sdata, "%.500s", fmtbuf);
closelog_r(&sdata);
#else
openlog(argv0 ? argv0 : ssh_progname, LOG_PID, log_facility);
#if !TARGET_OS_IPHONE
openlog(argv0 ? argv0 : ssh_progname, LOG_PID, log_facility);
syslog(pri, "%.500s", fmtbuf);
closelog();
#else
fprintf(thread_stderr, "%s (%s): ", argv0 ? argv0 : ssh_progname, log_facilities[log_facility].name);
fprintf(thread_stderr, "%.500s", fmtbuf);
#endif
#endif
}
errno = saved_errno;
Expand Down
3 changes: 2 additions & 1 deletion ssh_keygen/openbsd-compat/bsd-misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include "log.h"

#ifndef HAVE___PROGNAME
char *ssh_progname;
Expand Down Expand Up @@ -57,7 +58,7 @@ char *ssh_get_progname(char *argv0)
#endif
if ((q = strdup(p)) == NULL) {
perror("strdup");
exit(1);
cleanup_exit(1);
}
return q;
}
Expand Down
Loading

0 comments on commit f0cb2f4

Please sign in to comment.