comparison src/get.c @ 15:f671821d8222

code beautifying; 0 -> \0 if appropriate
author meillo@marmaro.de
date Thu, 06 Nov 2008 09:18:38 +0100
parents 26e34ae9a3e3
children dc89737b27aa
comparison
equal deleted inserted replaced
14:a8f3424347dc 15:f671821d8222
60 60
61 /* the name of the lock is constructed from the user 61 /* the name of the lock is constructed from the user
62 and the server name, to prevent more than one connection at the same time 62 and the server name, to prevent more than one connection at the same time
63 to the same server and the same user. This way concurrent connections 63 to the same server and the same user. This way concurrent connections
64 are possible to different servers or different users */ 64 are possible to different servers or different users */
65 hitch_name = g_strdup_printf("%s/masqmail-get-%s@%s-%d.lock", conf.lock_dir, gc->login_user, gc->server_name, getpid()); 65 hitch_name = g_strdup_printf("%s/masqmail-get-%s@%s-%d.lock",
66 lock_name = g_strdup_printf("%s/masqmail-get-%s@%s.lock", conf.lock_dir, gc->login_user, gc->server_name); 66 conf.lock_dir, gc->login_user, gc->server_name, getpid());
67 lock_name = g_strdup_printf("%s/masqmail-get-%s@%s.lock",
68 conf.lock_dir, gc->login_user, gc->server_name);
67 69
68 ok = dot_lock(lock_name, hitch_name); 70 ok = dot_lock(lock_name, hitch_name);
69 if (!ok) 71 if (!ok)
70 logwrite(LOG_WARNING, "getting mail for %s@%s is locked\n", gc->login_user, gc->server_name); 72 logwrite(LOG_WARNING, "getting mail for %s@%s is locked\n", gc->login_user, gc->server_name);
71 73
96 98
97 #ifdef USE_DOTLOCK 99 #ifdef USE_DOTLOCK
98 static gboolean 100 static gboolean
99 get_unlock(get_conf * gc) 101 get_unlock(get_conf * gc)
100 { 102 {
101 gchar *lock_name lock_name = g_strdup_printf("%s/masqmail-get-%s@%s.lock", conf.lock_dir, gc->login_user, gc->server_name); 103 gchar *lock_name lock_name = g_strdup_printf("%s/masqmail-get-%s@%s.lock",
104 conf.lock_dir, gc->login_user, gc->server_name);
102 105
103 dot_unlock(lock_name); 106 dot_unlock(lock_name);
104 g_free(lock_name); 107 g_free(lock_name);
105 108
106 return TRUE; 109 return TRUE;
107 } 110 }
108 #else 111 #else
109 static void 112 static void
110 get_unlock(get_conf * gc, int fd) 113 get_unlock(get_conf * gc, int fd)
111 { 114 {
112 gchar *lock_name = g_strdup_printf("%s/masqmail-get-%s@%s.lock", conf.lock_dir, gc->login_user, gc->server_name); 115 gchar *lock_name = g_strdup_printf("%s/masqmail-get-%s@%s.lock",
116 conf.lock_dir, gc->login_user, gc->server_name);
113 117
114 flock(fd, LOCK_UN); 118 flock(fd, LOCK_UN);
115 close(fd); 119 close(fd);
116 120
117 unlink(lock_name); 121 unlink(lock_name);
349 exit(EXIT_FAILURE); 353 exit(EXIT_FAILURE);
350 354
351 } 355 }
352 } 356 }
353 } else { 357 } else {
354 /* If select returns 0, the interval time has elapsed. 358 /* If select returns 0, the interval time has elapsed. We start a new get process */
355 We start a new get process */
356 int pid; 359 int pid;
357 signal(SIGCHLD, sigchld_handler); 360 signal(SIGCHLD, sigchld_handler);
358 if ((pid = fork()) == 0) { 361 if ((pid = fork()) == 0) {
359 get_online(); 362 get_online();
360 363
382 if (strcmp(gc->protocol, "pop3") == 0) { 385 if (strcmp(gc->protocol, "pop3") == 0) {
383 DEBUG(3) debugf("attempting to login for user %s, host = %s with pop3\n", gc->login_user, gc->server_name); 386 DEBUG(3) debugf("attempting to login for user %s, host = %s with pop3\n", gc->login_user, gc->server_name);
384 ok = pop3_login(gc->server_name, gc->server_port, resolve_list, gc->login_user, gc->login_pass, flags); 387 ok = pop3_login(gc->server_name, gc->server_port, resolve_list, gc->login_user, gc->login_pass, flags);
385 } else if (strcmp(gc->protocol, "apop") == 0) { 388 } else if (strcmp(gc->protocol, "apop") == 0) {
386 DEBUG(3) debugf ("attempting to login for user %s, host = %s with apop\n", gc->login_user, gc->server_name); 389 DEBUG(3) debugf ("attempting to login for user %s, host = %s with apop\n", gc->login_user, gc->server_name);
387 ok = pop3_login(gc->server_name, gc->server_port, resolve_list, gc->login_user, gc->login_pass, flags | POP3_FLAG_APOP); 390 ok = pop3_login(gc->server_name, gc->server_port, resolve_list, gc->login_user,
391 gc->login_pass, flags | POP3_FLAG_APOP);
388 } else { 392 } else {
389 logwrite(LOG_ALERT, "get protocol %s unknown\n", gc->protocol); 393 logwrite(LOG_ALERT, "get protocol %s unknown\n", gc->protocol);
390 } 394 }
391 return ok; 395 return ok;
392 } 396 }