Skip to content

Commit f0b3304

Browse files
Merge pull request #59 from saradickinson/os_logging
Fix logging on 10.11
2 parents 98d8306 + 85d483a commit f0b3304

File tree

3 files changed

+53
-27
lines changed

3 files changed

+53
-27
lines changed

ChangeLog

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
* 2017-12-18: Version 0.2.1
2+
* Fix use of logging on macos 10.11
3+
14
* 2017-12-18: Version 0.2.0
25
* Add Powershell scripts for Windows 7 that will update the IPv4 DNS resolvers.
36
* Add Windows scripts to enable a Scheduled task for stubby

configure.ac

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
AC_PREREQ([2.68])
2-
AC_INIT([Stubby], [0.2.0], [[email protected]])
2+
AC_INIT([Stubby], [0.2.1], [[email protected]])
33
AC_CANONICAL_TARGET
44
AM_INIT_AUTOMAKE
55
AC_CONFIG_SRCDIR([src/stubby.c])
@@ -54,6 +54,8 @@ AC_TRY_COMPILE([
5454
AC_MSG_RESULT(no)
5555
])
5656

57+
AC_CHECK_HEADERS([os/log.h])
58+
5759
build_on_windows="0"
5860
build_on_macos="0"
5961
build_on_unix="0"

macos/stubby-ui-helper.c

+47-26
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* requires privileges.
66
*/
77

8+
#include "config.h"
89
#include <ctype.h>
910
#include <errno.h>
1011
#include <stdio.h>
@@ -13,7 +14,9 @@
1314
#include <unistd.h>
1415

1516
#include <Security/Authorization.h>
17+
#ifdef HAVE_OS_LOG_H
1618
#include <os/log.h>
19+
#endif
1720

1821
static const char CP[] = "/bin/cp";
1922
static const char LAUNCHCTL[] = "/bin/launchctl";
@@ -24,11 +27,25 @@ static const char DEFAULT_CONFIG_FILE[] = "/usr/local/etc/stubby/stubby.yml";
2427
static const char RIGHT_DAEMON_RUN[] = "net.getdnsapi.stubby.daemon.run";
2528
static const char RIGHT_DNS_LOCAL[] = "net.getdnsapi.stubby.dns.local";
2629

30+
static void log_failure(const char *log_message)
31+
{
32+
fprintf(stderr, "failed: %s\n", log_message);
33+
#ifdef HAVE_OS_LOG_H
34+
os_log(OS_LOG_DEFAULT, "failed: %s", log_message);
35+
#endif
36+
}
37+
38+
#ifdef HAVE_OS_LOG_H
39+
static void log_action(const char *log_message)
40+
{
41+
os_log(OS_LOG_DEFAULT, "%s", log_message);
42+
}
43+
#endif
44+
2745
void check_auth(const char *auth, const char *right)
2846
{
2947
if (!auth) {
30-
fprintf(stderr, "Authorization required.");
31-
os_log(OS_LOG_DEFAULT, "Required authorization not supplied.");
48+
log_failure("Authorization required.");
3249
exit(1);
3350
}
3451

@@ -48,8 +65,7 @@ void check_auth(const char *auth, const char *right)
4865
continue;
4966
}
5067
}
51-
fprintf(stderr, "Invalid authorization key text.");
52-
os_log(OS_LOG_DEFAULT, "Invalid authorization key test.");
68+
log_failure("Invalid authorization key text.");
5369
exit(1);
5470
}
5571

@@ -58,8 +74,7 @@ void check_auth(const char *auth, const char *right)
5874

5975
oss = AuthorizationCreateFromExternalForm(&auth_ext_form, &auth_ref);
6076
if (oss != errAuthorizationSuccess) {
61-
fprintf(stderr, "Bad authorization key form.");
62-
os_log(OS_LOG_DEFAULT, "Authorization key is of wrong form.");
77+
log_failure("Bad authorization key form.");
6378
exit(1);
6479
}
6580

@@ -73,8 +88,7 @@ void check_auth(const char *auth, const char *right)
7388
kAuthorizationFlagExtendRights | kAuthorizationFlagInteractionAllowed,
7489
NULL);
7590
if (oss != errAuthorizationSuccess) {
76-
fprintf(stderr, "Authorization declined.");
77-
os_log(OS_LOG_DEFAULT, "Authorization declined.");
91+
log_failure("Authorization declined.");
7892
exit(1);
7993
}
8094

@@ -89,78 +103,85 @@ void usage()
89103

90104
void fail_with_errno(const char *op)
91105
{
92-
fprintf(stderr, "%s failed: %s.\n", op, strerror(errno));
93-
os_log(OS_LOG_DEFAULT, "%s failed: %s.", op, strerror(errno));
106+
log_failure(strerror(errno));
94107
exit(1);
95108
}
96109

97110
void start()
98111
{
99-
os_log(OS_LOG_DEFAULT, "Starting Stubby.");
100-
112+
#ifdef HAVE_OS_LOG_H
113+
log_action("Starting Stubby.");
114+
#endif
101115
int err = execl(LAUNCHCTL, LAUNCHCTL, "load", "/Library/LaunchDaemons/org.getdns.stubby.plist", NULL);
102116
if (err == -1)
103117
fail_with_errno("start");
104118
}
105119

106120
void stop()
107121
{
108-
os_log(OS_LOG_DEFAULT, "Stopping Stubby.");
109-
122+
#ifdef HAVE_OS_LOG_H
123+
log_action("Stopping Stubby.");
124+
#endif
110125
int err = execl(LAUNCHCTL, LAUNCHCTL, "unload", "/Library/LaunchDaemons/org.getdns.stubby.plist", NULL);
111126
if (err == -1)
112127
fail_with_errno("stop");
113128
}
114129

115130
void list()
116131
{
117-
os_log(OS_LOG_DEFAULT, "Checking Stubby.");
118-
132+
#ifdef HAVE_OS_LOG_H
133+
log_action("Checking Stubby.");
134+
#endif
119135
int err = execl(LAUNCHCTL, LAUNCHCTL, "list", "org.getdns.stubby", NULL);
120136
if (err == -1)
121137
fail_with_errno("stop");
122138
}
123139

124140
void dns_stubby()
125141
{
126-
os_log(OS_LOG_DEFAULT, "DNS resolving via Stubby.");
127-
142+
#ifdef HAVE_OS_LOG_H
143+
log_action("DNS resolving via Stubby.");
144+
#endif
128145
int err = execl(STUBBY_SETDNS, STUBBY_SETDNS, NULL);
129146
if (err == -1)
130147
fail_with_errno("dns_stubby");
131148
}
132149

133150
void dns_default()
134151
{
135-
os_log(OS_LOG_DEFAULT, "DNS resolving via defaults.");
136-
152+
#ifdef HAVE_OS_LOG_H
153+
log_action("DNS resolving via defaults.");
154+
#endif
137155
int err = execl(STUBBY_SETDNS, STUBBY_SETDNS, "-r", NULL);
138156
if (err == -1)
139157
fail_with_errno("dns_default");
140158
}
141159

142160
void dns_list()
143161
{
144-
os_log(OS_LOG_DEFAULT, "List DNS resolver.");
145-
162+
#ifdef HAVE_OS_LOG_H
163+
log_action("List DNS resolver.");
164+
#endif
146165
int err = execl(STUBBY_SETDNS, STUBBY_SETDNS, "-l", NULL);
147166
if (err == -1)
148167
fail_with_errno("dns_list");
149168
}
150169

151170
void check_config(const char *config_file)
152171
{
153-
os_log(OS_LOG_DEFAULT, "Check configuration.");
154-
172+
#ifdef HAVE_OS_LOG_H
173+
log_action("Check configuration.");
174+
#endif
155175
int err = execl(STUBBY, STUBBY, "-C", config_file, "-i", NULL);
156176
if (err == -1)
157177
fail_with_errno("check_config");
158178
}
159179

160180
void write_config(const char *config_file)
161181
{
162-
os_log(OS_LOG_DEFAULT, "Write configuration.");
163-
182+
#ifdef HAVE_OS_LOG_H
183+
log_action("Write configuration.");
184+
#endif
164185
int err = execl(CP, CP, config_file, DEFAULT_CONFIG_FILE, NULL);
165186
if (err == -1)
166187
fail_with_errno("write_config");

0 commit comments

Comments
 (0)