+/* Print the given message to standard error. Avoids stdio. */
+static void printerr(const char *p) { write(STDERR_FILENO, p, strlen(p)); }
+
+/* Create the socket directory, being careful about permissions. */
+static void create_sockdir(void)
+{
+ struct stat st;
+
+ if (stat(sockdir, &st)) {
+ if (errno == ENOENT) {
+ if (mkdir(sockdir, 0700)) {
+ perror("noip: creating socketdir");
+ exit(127);
+ }
+ if (!stat(sockdir, &st))
+ goto check;
+ }
+ perror("noip: checking socketdir");
+ exit(127);
+ }
+check:
+ if (!S_ISDIR(st.st_mode)) {
+ printerr("noip: bad socketdir: not a directory\n");
+ exit(127);
+ }
+ if (st.st_uid != uid) {
+ printerr("noip: bad socketdir: not owner\n");
+ exit(127);
+ }
+ if (st.st_mode & 077) {
+ printerr("noip: bad socketdir: not private\n");
+ exit(127);
+ }
+}
+
+/* Initialization function. */
+static void setup(void) __attribute__((constructor));