comparison src/online.c @ 10:26e34ae9a3e3

changed indention and line wrapping to a more consistent style
author meillo@marmaro.de
date Mon, 27 Oct 2008 16:23:10 +0100
parents 08114f7dcc23
children f671821d8222
comparison
equal deleted inserted replaced
9:31cc8a89cb74 10:26e34ae9a3e3
22 #include "mserver.h" 22 #include "mserver.h"
23 #include "peopen.h" 23 #include "peopen.h"
24 24
25 gchar *connection_name; 25 gchar *connection_name;
26 26
27 void set_online_name(gchar *name) 27 void
28 set_online_name(gchar * name)
28 { 29 {
29 connection_name = g_strdup(name); 30 connection_name = g_strdup(name);
30 } 31 }
31 32
32 static 33 static gchar*
33 gchar *detect_online_pipe(const gchar *pipe) 34 detect_online_pipe(const gchar * pipe)
34 { 35 {
35 pid_t pid; 36 pid_t pid;
36 void (*old_signal)(int); 37 void (*old_signal) (int);
37 int status; 38 int status;
38 FILE *in; 39 FILE *in;
39 gchar *name = NULL; 40 gchar *name = NULL;
40 41
41 old_signal = signal(SIGCHLD, SIG_DFL); 42 old_signal = signal(SIGCHLD, SIG_DFL);
42 43
43 in = peopen(pipe, "r", environ, &pid); 44 in = peopen(pipe, "r", environ, &pid);
44 if(in != NULL){ 45 if (in != NULL) {
45 gchar output[256]; 46 gchar output[256];
46 if(fgets(output, 255, in)){ 47 if (fgets(output, 255, in)) {
47 g_strchomp(output); 48 g_strchomp(output);
48 name = g_strdup(output); 49 name = g_strdup(output);
49 } 50 }
50 fclose(in); 51 fclose(in);
51 waitpid(pid, &status, 0); 52 waitpid(pid, &status, 0);
52 if(WEXITSTATUS(status) != EXIT_SUCCESS){ 53 if (WEXITSTATUS(status) != EXIT_SUCCESS) {
53 g_free(name); 54 g_free(name);
54 name = NULL; 55 name = NULL;
55 } 56 }
56 }else 57 } else
57 logwrite(LOG_ALERT, "could not open pipe '%s': %s\n", pipe, strerror(errno)); 58 logwrite(LOG_ALERT, "could not open pipe '%s': %s\n", pipe, strerror(errno));
58 59
59 signal(SIGCHLD, old_signal); 60 signal(SIGCHLD, old_signal);
60 61
61 return name; 62 return name;
62 } 63 }
63 64
64 gchar *detect_online() 65 gchar*
66 detect_online()
65 { 67 {
66 if(conf.online_detect != NULL){ 68 if (conf.online_detect != NULL) {
67 if(strcmp(conf.online_detect, "file") == 0){ 69 if (strcmp(conf.online_detect, "file") == 0) {
68 DEBUG(3) debugf("online detection method 'file'\n"); 70 DEBUG(3) debugf("online detection method 'file'\n");
69 if(conf.online_file != NULL){ 71 if (conf.online_file != NULL) {
70 struct stat st; 72 struct stat st;
71 if(stat(conf.online_file, &st) == 0){ 73 if (stat(conf.online_file, &st) == 0) {
72 FILE *fptr = fopen(conf.online_file, "r"); 74 FILE *fptr = fopen(conf.online_file, "r");
73 if(fptr){ 75 if (fptr) {
74 char buf[256]; 76 char buf[256];
75 fgets(buf, 256, fptr); 77 fgets(buf, 256, fptr);
76 g_strchomp(buf); 78 g_strchomp(buf);
77 fclose(fptr); 79 fclose(fptr);
78 return g_strdup(buf); 80 return g_strdup(buf);
79 }else{ 81 } else {
80 logwrite(LOG_ALERT, "opening of %s failed: %s\n", 82 logwrite(LOG_ALERT, "opening of %s failed: %s\n", conf.online_file, strerror(errno));
81 conf.online_file, strerror(errno)); 83 return NULL;
82 return NULL; 84 }
83 } 85 } else if (errno == ENOENT) {
86 logwrite(LOG_NOTICE, "not online.\n");
87 return NULL;
88 } else {
89 logwrite(LOG_ALERT, "stat of %s failed: %s", conf.online_file, strerror(errno));
90 return NULL;
91 }
92 } else
93 logwrite(LOG_ALERT, "online detection mode is 'file', but online_file is undefined\n");
94 #ifdef ENABLE_MSERVER
95 } else if (strcmp(conf.online_detect, "mserver") == 0) {
96 DEBUG(3) debugf("connection method 'mserver'\n");
97 return mserver_detect_online(conf.mserver_iface);
98 #endif
99 } else if (strcmp(conf.online_detect, "pipe") == 0) {
100 DEBUG(3) debugf("connection method 'pipe'\n");
101 if (conf.online_pipe)
102 return detect_online_pipe(conf.online_pipe);
103 else {
104 logwrite(LOG_ALERT, "online detection mode is 'pipe', but online_pipe is undefined\n");
105 return NULL;
106 }
107 } else if (strcmp(conf.online_detect, "argument") == 0) {
108 return connection_name;
109 } else {
110 DEBUG(3) debugf("no connection method selected\n");
111 }
84 } 112 }
85 else if(errno == ENOENT){
86 logwrite(LOG_NOTICE, "not online.\n");
87 return NULL;
88 }else{
89 logwrite(LOG_ALERT, "stat of %s failed: %s",
90 conf.online_file, strerror(errno));
91 return NULL;
92 }
93 }else
94 logwrite(LOG_ALERT,
95 "online detection mode is 'file', "
96 "but online_file is undefined\n");
97 #ifdef ENABLE_MSERVER
98 }else if(strcmp(conf.online_detect, "mserver") == 0){
99 DEBUG(3) debugf("connection method 'mserver'\n");
100 return mserver_detect_online(conf.mserver_iface);
101 #endif
102 }else if(strcmp(conf.online_detect, "pipe") == 0){
103 DEBUG(3) debugf("connection method 'pipe'\n");
104 if(conf.online_pipe)
105 return detect_online_pipe(conf.online_pipe);
106 else{
107 logwrite(LOG_ALERT,
108 "online detection mode is 'pipe', "
109 "but online_pipe is undefined\n");
110 return NULL; 113 return NULL;
111 }
112 }else if(strcmp(conf.online_detect, "argument") == 0){
113 return connection_name;
114 }else{
115 DEBUG(3) debugf("no connection method selected\n");
116 }
117 }
118 return NULL;
119 } 114 }