[dovecot-cvs] dovecot/src/master main.c, 1.105, 1.106 ssl-init-main.c, 1.2, 1.3 ssl-init.c, 1.27, 1.28 ssl-init.h, 1.5, 1.6
tss at dovecot.org
tss at dovecot.org
Sun May 13 16:45:53 EEST 2007
- Previous message: [dovecot-cvs] dovecot/src/master main.c, 1.80.2.21, 1.80.2.22 ssl-init-main.c, 1.2, 1.2.2.1 ssl-init.c, 1.25.2.2, 1.25.2.3 ssl-init.h, 1.5, 1.5.2.1
- Next message: [dovecot-cvs] dovecot/src/deliver deliver.c, 1.20.2.38, 1.20.2.39 smtp-client.c, 1.1.2.2, 1.1.2.3
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /var/lib/cvs/dovecot/src/master
In directory talvi:/tmp/cvs-serv13627
Modified Files:
main.c ssl-init-main.c ssl-init.c ssl-init.h
Log Message:
When running multiple Dovecot instances, only one of them needs to
regenerate ssl-parameters.dat.
Index: main.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/master/main.c,v
retrieving revision 1.105
retrieving revision 1.106
diff -u -d -r1.105 -r1.106
--- main.c 11 May 2007 13:29:25 -0000 1.105
+++ main.c 13 May 2007 13:45:49 -0000 1.106
@@ -233,6 +233,9 @@
i_error("unknown child %s exited "
"successfully", dec2str(pid));
}
+ } else if (status == 1 &&
+ process_type == PROCESS_TYPE_SSL_PARAM) {
+ /* kludgy. hide this failure. */
} else {
msg = get_exit_status_message(status);
msg = msg == NULL ? "" :
@@ -256,7 +259,7 @@
mail_process_destroyed(pid);
break;
case PROCESS_TYPE_SSL_PARAM:
- ssl_parameter_process_destroyed(pid);
+ ssl_parameter_process_destroyed(abnormal_exit);
break;
case PROCESS_TYPE_DICT:
dict_process_restart();
Index: ssl-init-main.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/master/ssl-init-main.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- ssl-init-main.c 7 Feb 2006 12:38:04 -0000 1.2
+++ ssl-init-main.c 13 May 2007 13:45:49 -0000 1.3
@@ -2,6 +2,7 @@
#include "lib.h"
#include "lib-signals.h"
+#include "file-lock.h"
#include "randgen.h"
#include "ssl-init.h"
@@ -11,17 +12,17 @@
#include <sys/stat.h>
#ifdef HAVE_SSL
-static void generate_parameters_file(const char *fname)
+static int generate_parameters_file(const char *fname)
{
const char *temp_fname;
+ struct file_lock *lock;
mode_t old_mask;
- int fd;
+ int fd, ret;
temp_fname = t_strconcat(fname, ".tmp", NULL);
- (void)unlink(temp_fname);
old_mask = umask(0);
- fd = open(temp_fname, O_WRONLY | O_CREAT | O_EXCL, 0644);
+ fd = open(temp_fname, O_WRONLY | O_CREAT, 0644);
umask(old_mask);
if (fd == -1) {
@@ -29,25 +30,42 @@
temp_fname);
}
- _ssl_generate_parameters(fd, temp_fname);
+ /* If multiple dovecot instances are running, only one of them needs
+ to regenerate this file. */
+ ret = file_try_lock(fd, temp_fname, F_WRLCK,
+ FILE_LOCK_METHOD_FCNTL, &lock);
+ if (ret < 0)
+ i_fatal("file_try_lock(%s) failed: %m", temp_fname);
+ if (ret == 0) {
+ /* someone else is writing this */
+ return -1;
+ }
+ if (ftruncate(fd, 0) < 0)
+ i_fatal("ftruncate(%s) failed: %m", temp_fname);
- if (close(fd) < 0)
- i_fatal("close(%s) failed: %m", temp_fname);
+ _ssl_generate_parameters(fd, temp_fname);
if (rename(temp_fname, fname) < 0)
i_fatal("rename(%s, %s) failed: %m", temp_fname, fname);
+ if (close(fd) < 0)
+ i_fatal("close(%s) failed: %m", temp_fname);
+ file_lock_free(&lock);
i_info("SSL parameters regeneration completed");
+ return 0;
}
#else
-static void generate_parameters_file(const char *fname __attr_unused__)
+static int generate_parameters_file(const char *fname __attr_unused__)
{
i_fatal("Dovecot built without SSL support");
+ return -1;
}
#endif
int main(int argc, char *argv[])
{
+ int ret;
+
lib_init();
i_set_failure_internal();
@@ -55,9 +73,10 @@
i_fatal("Usage: ssl-build-param <path>");
random_init();
- generate_parameters_file(argv[1]);
+ if (generate_parameters_file(argv[1]) < 0)
+ ret = 1;
random_deinit();
lib_deinit();
- return 0;
+ return ret;
}
Index: ssl-init.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/master/ssl-init.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- ssl-init.c 26 Jun 2006 08:56:28 -0000 1.27
+++ ssl-init.c 13 May 2007 13:45:49 -0000 1.28
@@ -60,11 +60,14 @@
i_fatal_status(FATAL_EXEC, "execv(%s) failed: %m", binpath);
}
-void ssl_parameter_process_destroyed(pid_t pid __attr_unused__)
+void ssl_parameter_process_destroyed(bool abnormal_exit)
{
- if (file_copy(SSL_PARAMETERS_PERM_PATH, generating_path, TRUE) <= 0) {
- i_error("file_copy(%s, %s) failed: %m",
- SSL_PARAMETERS_PERM_PATH, generating_path);
+ if (!abnormal_exit) {
+ if (file_copy(SSL_PARAMETERS_PERM_PATH,
+ generating_path, TRUE) <= 0) {
+ i_error("file_copy(%s, %s) failed: %m",
+ SSL_PARAMETERS_PERM_PATH, generating_path);
+ }
}
i_free_and_null(generating_path);
}
Index: ssl-init.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/master/ssl-init.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- ssl-init.h 5 Feb 2006 18:00:15 -0000 1.5
+++ ssl-init.h 13 May 2007 13:45:49 -0000 1.6
@@ -3,7 +3,7 @@
#define SSL_PARAMETERS_FILENAME "ssl-parameters.dat"
-void ssl_parameter_process_destroyed(pid_t pid);
+void ssl_parameter_process_destroyed(bool abnormal_exit);
void ssl_check_parameters_file(void);
void _ssl_generate_parameters(int fd, const char *fname);
- Previous message: [dovecot-cvs] dovecot/src/master main.c, 1.80.2.21, 1.80.2.22 ssl-init-main.c, 1.2, 1.2.2.1 ssl-init.c, 1.25.2.2, 1.25.2.3 ssl-init.h, 1.5, 1.5.2.1
- Next message: [dovecot-cvs] dovecot/src/deliver deliver.c, 1.20.2.38, 1.20.2.39 smtp-client.c, 1.1.2.2, 1.1.2.3
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the dovecot-cvs
mailing list