[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r3594 - GNUnet/src/util/os
From: |
durner |
Subject: |
[GNUnet-SVN] r3594 - GNUnet/src/util/os |
Date: |
Wed, 1 Nov 2006 03:27:37 -0800 (PST) |
Author: durner
Date: 2006-11-01 03:27:31 -0800 (Wed, 01 Nov 2006)
New Revision: 3594
Modified:
GNUnet/src/util/os/osconfig.c
Log:
reformat
Modified: GNUnet/src/util/os/osconfig.c
===================================================================
--- GNUnet/src/util/os/osconfig.c 2006-11-01 05:41:58 UTC (rev 3593)
+++ GNUnet/src/util/os/osconfig.c 2006-11-01 11:27:31 UTC (rev 3594)
@@ -32,60 +32,60 @@
* @brief Enumerate all network interfaces
* @param callback the callback function
*/
-void os_list_network_interfaces(struct GE_Context * ectx,
- NetworkIfcProcessor proc,
- void * cls) {
+void os_list_network_interfaces(struct GE_Context *ectx,
+ NetworkIfcProcessor proc, void *cls)
+{
#ifdef MINGW
ListNICs(proc, cls);
#else
char entry[11], *dst;
FILE *f;
- if (system("ifconfig > /dev/null 2> /dev/null"))
- if (system("/sbin/ifconfig > /dev/null 2> /dev/null") == 0)
+ if(system("ifconfig > /dev/null 2> /dev/null"))
+ if(system("/sbin/ifconfig > /dev/null 2> /dev/null") == 0)
f = popen("/sbin/ifconfig 2> /dev/null", "r");
else
f = NULL;
else
f = popen("ifconfig 2> /dev/null", "r");
- if (!f) {
+ if(!f)
+ {
GE_LOG_STRERROR_FILE(ectx,
- GE_USER | GE_ADMIN | GE_BULK | GE_WARNING,
- "popen",
- "ifconfig");
+ GE_USER | GE_ADMIN | GE_BULK | GE_WARNING,
+ "popen", "ifconfig");
return;
}
- while(1) {
+ while(1)
+ {
int i = 0;
int c = fgetc(f);
- if (c == EOF)
+ if(c == EOF)
break;
dst = entry;
/* Read interface name until the first space (or colon under OS X) */
- while (c != EOF && c != '\n' &&
+ while(c != EOF && c != '\n' &&
#ifdef OSX
- c != ':'
+ c != ':'
#else
- c != ' '
+ c != ' '
#endif
- && i < 10) {
+ && i < 10)
+ {
*dst++ = c;
i++;
c = fgetc(f);
}
*dst = 0;
- if ( (entry[0] != '\0') &&
- (OK != proc(entry,
- strcmp(entry, "eth0") == 0,
- cls)) )
+ if((entry[0] != '\0') &&
+ (OK != proc(entry, strcmp(entry, "eth0") == 0, cls)))
break;
- while ((c != '\n') && (c != EOF))
+ while((c != '\n') && (c != EOF))
c = fgetc(f);
}
pclose(f);
@@ -96,13 +96,13 @@
* @brief Checks if we can start GNUnet automatically
* @return 1 if yes, 0 otherwise
*/
-static int isOSAutostartCapable() {
+static int isOSAutostartCapable()
+{
#ifdef LINUX
- if (ACCESS("/usr/sbin/update-rc.d",
- X_OK) == 0) {
+ if(ACCESS("/usr/sbin/update-rc.d", X_OK) == 0)
+ {
/* Debian */
- if (ACCESS("/etc/init.d/",
- W_OK) == 0)
+ if(ACCESS("/etc/init.d/", W_OK) == 0)
return 1;
}
return 0;
@@ -115,95 +115,106 @@
#endif
}
-int os_modify_autostart(struct GE_Context * ectx,
- int testCapability,
- int doAutoStart,
- const char * application,
- const char * username,
- const char * groupname) {
- if (testCapability) {
+int os_modify_autostart(struct GE_Context *ectx,
+ int testCapability,
+ int doAutoStart,
+ const char *application,
+ const char *username, const char *groupname)
+{
+ if(testCapability)
+ {
/* TODO: check that user/group/application
exist! */
return isOSAutostartCapable();
}
#ifdef WINDOWS
- if (doAutoStart) {
- if (IsWinNT()) {
+ if(doAutoStart)
+ {
+ if(IsWinNT())
+ {
char *err = NULL;
DWORD dwErr = 0;
- if (username && !strlen(username))
- username = NULL;
+ if(username && !strlen(username))
+ username = NULL;
/* Install service */
- switch (InstallAsService(username)) {
- case 0:
- case 1:
- break;
- case 2:
- if (GetLastError() != ERROR_SERVICE_EXISTS)
- return 1;
- case 3:
- return 2;
- default:
- return -1;
+ switch (InstallAsService(username))
+ {
+ case 0:
+ case 1:
+ break;
+ case 2:
+ if(GetLastError() != ERROR_SERVICE_EXISTS)
+ return 1;
+ case 3:
+ return 2;
+ default:
+ return -1;
}
/* Grant permissions to the GNUnet directory */
- if ((!err || dwErr == ERROR_SERVICE_EXISTS) && username) {
- char szHome[_MAX_PATH + 1];
-
- plibc_conv_to_win_path("/", szHome);
-
- if (!AddPathAccessRights(szHome, username, GENERIC_ALL))
- return 3;
+ if((!err || dwErr == ERROR_SERVICE_EXISTS) && username)
+ {
+ char szHome[_MAX_PATH + 1];
+
+ plibc_conv_to_win_path("/", szHome);
+
+ if(!AddPathAccessRights(szHome, username, GENERIC_ALL))
+ return 3;
}
- } else {
+ }
+ else
+ {
char szPath[_MAX_PATH + 1];
HKEY hKey;
plibc_conv_to_win_path(application, szPath);
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
- "Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0,
KEY_EXECUTE,
- &hKey) == ERROR_SUCCESS) {
- if (RegSetValueEx(hKey,
- "GNUnet",
- 0,
- REG_SZ,
- szPath,
- strlen(szPath)) != ERROR_SUCCESS)
- return 4;
-
- RegCloseKey(hKey);
- } else
- return 4;
+ "Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0,
+ KEY_EXECUTE, &hKey) == ERROR_SUCCESS)
+ {
+ if(RegSetValueEx(hKey,
+ "GNUnet",
+ 0, REG_SZ, szPath, strlen(szPath)) != ERROR_SUCCESS)
+ return 4;
+
+ RegCloseKey(hKey);
+ }
+ else
+ return 4;
}
- } else {
- if (IsWinNT()) {
- switch (UninstallService()) {
- case 0:
- case 1:
- break;
- case 2:
- return 1;
- case 3:
- return 5;
- case 4:
- return 6;
- default:
- return -1;
+ }
+ else
+ {
+ if(IsWinNT())
+ {
+ switch (UninstallService())
+ {
+ case 0:
+ case 1:
+ break;
+ case 2:
+ return 1;
+ case 3:
+ return 5;
+ case 4:
+ return 6;
+ default:
+ return -1;
}
- } else {
+ }
+ else
+ {
HKEY hKey;
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
- "Software\\Microsoft\\Windows\\CurrentVersion\\Run",
- 0,
- KEY_SET_VALUE,
- &hKey) == ERROR_SUCCESS) {
- RegDeleteValue(hKey, "GNUnet");
- RegCloseKey(hKey);
+ "Software\\Microsoft\\Windows\\CurrentVersion\\Run",
+ 0, KEY_SET_VALUE, &hKey) == ERROR_SUCCESS)
+ {
+ RegDeleteValue(hKey, "GNUnet");
+ RegCloseKey(hKey);
}
}
}
@@ -211,107 +222,102 @@
struct stat buf;
/* Unix */
- if ( (ACCESS("/usr/sbin/update-rc.d",
- X_OK) != 0) ) {
+ if((ACCESS("/usr/sbin/update-rc.d", X_OK) != 0))
+ {
GE_LOG_STRERROR_FILE(ectx,
- GE_ERROR | GE_USER | GE_ADMIN | GE_IMMEDIATE,
- "access",
- "/usr/sbin/update-rc.d");
+ GE_ERROR | GE_USER | GE_ADMIN | GE_IMMEDIATE,
+ "access", "/usr/sbin/update-rc.d");
return SYSERR;
}
/* Debian */
- if (doAutoStart) {
- if (ACCESS(application,
- X_OK) != 0) {
+ if(doAutoStart)
+ {
+ if(ACCESS(application, X_OK) != 0)
+ {
GE_LOG_STRERROR_FILE(ectx,
- GE_ERROR | GE_USER | GE_ADMIN | GE_IMMEDIATE,
- "access",
- application);
+ GE_ERROR | GE_USER | GE_ADMIN | GE_IMMEDIATE,
+ "access", application);
}
- if (STAT("/etc/init.d/gnunetd",
- &buf) == -1) {
+ if(STAT("/etc/init.d/gnunetd", &buf) == -1)
+ {
/* create init file */
- FILE * f = FOPEN("/etc/init.d/gnunetd", "w");
- if (! f) {
- GE_LOG_STRERROR_FILE(ectx,
- GE_ERROR | GE_USER | GE_ADMIN | GE_IMMEDIATE,
- "fopen",
- "/etc/init.d/gnunetd");
- return 1;
+ FILE *f = FOPEN("/etc/init.d/gnunetd", "w");
+ if(!f)
+ {
+ GE_LOG_STRERROR_FILE(ectx,
+ GE_ERROR | GE_USER | GE_ADMIN | GE_IMMEDIATE,
+ "fopen", "/etc/init.d/gnunetd");
+ return 1;
}
fprintf(f,
- "#!/bin/sh\n"
- "#\n"
- "# Automatically created by %s\n"
- "#\n"
- "\n"
- "PIDFILE=/var/run/gnunetd/gnunetd.pid\n"
- "\n"
- "case \"$1\" in\n"
- " start)\n"
- " echo -n \"Starting GNUnet: \"\n"
- " %s\n && echo ok || echo failed\n"
- " ;;\n"
- " stop)\n"
- " echo -n \"Stopping GNUnet: \"\n"
- " kill `cat $PIDFILE`\n && echo ok || echo failed\n"
- " ;;\n"
- " reload)\n"
- " echo -n \"Reloading GNUnet: \"\n"
- " kill -HUP `cat $PIDFILE`\n && echo ok || echo failed\n"
- " ;;\n"
- " restart|force-reload)\n"
- " echo \"Restarting GNUnet: gnunetd...\"\n"
- " $0 stop\n"
- " sleep 1\n"
- " $0 start\n"
- " ;;\n"
- " *)\n"
- " echo \"Usage: /etc/init.d/gnunetd
{start|stop|reload|restart|force-reload}\" >&2\n"
- " exit 1\n"
- " ;;\n"
- "\n"
- "esac\n"
- "exit 0\n",
- "gnunet-setup",
- application);
+ "#!/bin/sh\n"
+ "#\n"
+ "# Automatically created by %s\n"
+ "#\n"
+ "\n"
+ "PIDFILE=/var/run/gnunetd/gnunetd.pid\n"
+ "\n"
+ "case \"$1\" in\n"
+ " start)\n"
+ " echo -n \"Starting GNUnet: \"\n"
+ " %s\n && echo ok || echo failed\n"
+ " ;;\n"
+ " stop)\n"
+ " echo -n \"Stopping GNUnet: \"\n"
+ " kill `cat $PIDFILE`\n && echo ok || echo
failed\n"
+ " ;;\n"
+ " reload)\n"
+ " echo -n \"Reloading GNUnet: \"\n"
+ " kill -HUP `cat $PIDFILE`\n && echo ok || echo
failed\n"
+ " ;;\n"
+ " restart|force-reload)\n"
+ " echo \"Restarting GNUnet: gnunetd...\"\n"
+ " $0 stop\n"
+ " sleep 1\n"
+ " $0 start\n"
+ " ;;\n"
+ " *)\n"
+ " echo \"Usage: /etc/init.d/gnunetd
{start|stop|reload|restart|force-reload}\" >&2\n"
+ " exit 1\n"
+ " ;;\n"
+ "\n" "esac\n" "exit 0\n", "gnunet-setup", application);
fclose(f);
- if (0 != CHMOD("/etc/init.d/gnunetd",
- S_IRWXU | S_IRGRP | S_IXGRP |
- S_IROTH | S_IXOTH)) {
- GE_LOG_STRERROR_FILE(ectx,
- GE_WARNING | GE_USER | GE_ADMIN | GE_IMMEDIATE,
- "chmod",
- "/etc/init.d/gnunetd");
- return SYSERR;
+ if(0 != CHMOD("/etc/init.d/gnunetd",
+ S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH))
+ {
+ GE_LOG_STRERROR_FILE(ectx,
+ GE_WARNING | GE_USER | GE_ADMIN | GE_IMMEDIATE,
+ "chmod", "/etc/init.d/gnunetd");
+ return SYSERR;
}
}
errno = 0;
- if (-1 == system("/usr/sbin/update-rc.d gnunetd defaults")) {
+ if(-1 == system("/usr/sbin/update-rc.d gnunetd defaults"))
+ {
GE_LOG_STRERROR_FILE(ectx,
- GE_WARNING | GE_USER | GE_ADMIN | GE_IMMEDIATE,
- "system",
- "/usr/sbin/update-rc.d");
+ GE_WARNING | GE_USER | GE_ADMIN | GE_IMMEDIATE,
+ "system", "/usr/sbin/update-rc.d");
return SYSERR;
}
return OK;
- } else { /* REMOVE autostart */
- if ( (UNLINK("/etc/init.d/gnunetd") == -1) &&
- (errno != ENOENT)) {
+ }
+ else
+ { /* REMOVE autostart */
+ if((UNLINK("/etc/init.d/gnunetd") == -1) && (errno != ENOENT))
+ {
GE_LOG_STRERROR_FILE(ectx,
- GE_WARNING | GE_USER | GE_ADMIN | GE_IMMEDIATE,
- "unlink",
- "/etc/init.d/gnunetd");
+ GE_WARNING | GE_USER | GE_ADMIN | GE_IMMEDIATE,
+ "unlink", "/etc/init.d/gnunetd");
return SYSERR;
}
errno = 0;
- if (-1 != system("/usr/sbin/update-rc.d gnunetd remove")) {
+ if(-1 != system("/usr/sbin/update-rc.d gnunetd remove"))
+ {
GE_LOG_STRERROR_FILE(ectx,
- GE_WARNING | GE_USER | GE_ADMIN | GE_IMMEDIATE,
- "system",
- "/usr/sbin/update-rc.d");
+ GE_WARNING | GE_USER | GE_ADMIN | GE_IMMEDIATE,
+ "system", "/usr/sbin/update-rc.d");
return SYSERR;
}
return OK;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r3594 - GNUnet/src/util/os,
durner <=