This patch doesn't fix any bugs, it just makes dd_create API easier to use
Please review.
--
vda
diff -x '*.po' -d -urpN abrt.4/inc/dump_dir.h abrt.5/inc/dump_dir.h
--- abrt.4/inc/dump_dir.h 2010-09-23 16:48:44.000000000 +0200
+++ abrt.5/inc/dump_dir.h 2010-10-14 12:09:11.364115294 +0200
@@ -43,8 +43,8 @@ struct dump_dir *dd_init(void);
void dd_close(struct dump_dir *dd);
int dd_opendir(struct dump_dir *dd, const char *dir, int flags);
+struct dump_dir *dd_create(const char *dir, uid_t uid);
int dd_exist(struct dump_dir *dd, const char *path);
-int dd_create(struct dump_dir *dd, const char *dir, uid_t uid);
DIR *dd_init_next_file(struct dump_dir *dd);
int dd_get_next_file(struct dump_dir *dd, char **short_name, char **full_name);
diff -x '*.po' -d -urpN abrt.4/lib/plugins/KerneloopsScanner.cpp
abrt.5/lib/plugins/KerneloopsScanner.cpp
--- abrt.4/lib/plugins/KerneloopsScanner.cpp 2010-10-14 03:19:18.841369016 +0200
+++ abrt.5/lib/plugins/KerneloopsScanner.cpp 2010-10-14 12:09:11.364115294 +0200
@@ -132,8 +132,8 @@ int save_oops_to_debug_dump(GList **oops
char *second_line = (char*)strchr(first_line, '\n'); /* never NULL */
*second_line++ = '\0';
- struct dump_dir *dd = dd_init();
- if (dd_create(dd, path, /*uid:*/ 0))
+ struct dump_dir *dd = dd_create(path, /*uid:*/ 0);
+ if (dd)
{
dd_save_text(dd, FILENAME_ANALYZER, "Kerneloops");
dd_save_text(dd, FILENAME_EXECUTABLE, "kernel");
@@ -143,10 +143,10 @@ int save_oops_to_debug_dump(GList **oops
/* Optional, makes generated bz more informative */
strchrnul(second_line, '\n')[0] = '\0';
dd_save_text(dd, FILENAME_REASON, second_line);
+ dd_close(dd);
}
else
errors++;
- dd_close(dd);
}
return errors;
diff -x '*.po' -d -urpN abrt.4/lib/utils/dump_dir.c abrt.5/lib/utils/dump_dir.c
--- abrt.4/lib/utils/dump_dir.c 2010-10-14 12:02:09.921365132 +0200
+++ abrt.5/lib/utils/dump_dir.c 2010-10-14 12:11:58.139114083 +0200
@@ -220,8 +220,10 @@ int dd_opendir(struct dump_dir *dd, cons
* Currently, we set dir's gid to passwd(uid)->pw_gid parameter, and we set uid
to
* abrt's user id. We do not allow write access to group.
*/
-int dd_create(struct dump_dir *dd, const char *dir, uid_t uid)
+struct dump_dir *dd_create(const char *dir, uid_t uid)
{
+ struct dump_dir *dd = dd_init();
+
if (dd->locked)
error_msg_and_die("dump_dir is already opened"); /* bug */
@@ -236,20 +238,20 @@ int dd_create(struct dump_dir *dd, const
if (mkdir(dd->dd_dir, 0750) == -1)
{
perror_msg("Can't create dir '%s'", dir);
- dd_unlock(dd);
- return 0;
+ dd_close(dd);
+ return NULL;
}
/* mkdir's mode (above) can be affected by umask, fix it */
if (chmod(dd->dd_dir, 0750) == -1)
{
perror_msg("Can't change mode of '%s'", dd->dd_dir);
- dd_unlock(dd);
- return 0;
+ dd_close(dd);
+ return NULL;
}
/* Get ABRT's user id */
- dd->dd_uid = 0;
+ /*dd->dd_uid = 0; - dd_init did this already */
struct passwd *pw = getpwnam("abrt");
if (pw)
dd->dd_uid = pw->pw_uid;
@@ -257,7 +259,7 @@ int dd_create(struct dump_dir *dd, const
error_msg("User 'abrt' does not exist, using uid 0");
/* Get crashed application's group id */
- dd->dd_gid = 0;
+ /*dd->dd_gid = 0; - dd_init did this already */
pw = getpwuid(uid);
if (pw)
dd->dd_gid = pw->pw_gid;
@@ -293,7 +295,7 @@ int dd_create(struct dump_dir *dd, const
sprintf(long_str, "%lu", (long)t);
dd_save_text(dd, FILENAME_TIME, long_str);
- return 1;
+ return dd;
}
static void delete_file_dir(const char *dir)
diff -x '*.po' -d -urpN abrt.4/src/daemon/abrt-server.c
abrt.5/src/daemon/abrt-server.c
--- abrt.4/src/daemon/abrt-server.c 2010-10-12 17:30:28.000000000 +0200
+++ abrt.5/src/daemon/abrt-server.c 2010-10-14 12:09:11.367115336 +0200
@@ -115,11 +115,9 @@ static void create_debug_dump()
/* No need to check the path length, as all variables used are limited, and
dd_create()
fails if the path is too long. */
- struct dump_dir *dd = dd_init();
- if (!dd_create(dd, path, client_uid))
+ struct dump_dir *dd = dd_create(path, client_uid);
+ if (!dd)
{
- dd_delete(dd);
- dd_close(dd);
error_msg_and_die("Error creating crash dump %s", path);
}
diff -x '*.po' -d -urpN abrt.4/src/hooks/abrt-hook-ccpp.cpp
abrt.5/src/hooks/abrt-hook-ccpp.cpp
--- abrt.4/src/hooks/abrt-hook-ccpp.cpp 2010-10-14 01:11:22.000000000 +0200
+++ abrt.5/src/hooks/abrt-hook-ccpp.cpp 2010-10-14 12:09:11.368115860 +0200
@@ -415,8 +415,8 @@ int main(int argc, char** argv)
if (path_len >= (sizeof(path) - sizeof("/"FILENAME_COREDUMP)))
return 1;
- struct dump_dir *dd = dd_init();
- if (dd_create(dd, path, uid))
+ struct dump_dir *dd = dd_create(path, uid);
+ if (dd)
{
char *cmdline = get_cmdline(pid); /* never NULL */
char *reason = xasprintf("Process %s was killed by signal %s
(SIG%s)", executable, signal_str, signame ? signame : signal_str);