summaryrefslogtreecommitdiffstats
path: root/policy.c
diff options
context:
space:
mode:
Diffstat (limited to 'policy.c')
-rw-r--r--policy.c27
1 files changed, 11 insertions, 16 deletions
diff --git a/policy.c b/policy.c
index dfaafdc..f417a9a 100644
--- a/policy.c
+++ b/policy.c
@@ -23,6 +23,8 @@
*/
#include "mdadm.h"
+#include "xmalloc.h"
+
#include <dirent.h>
#include <fnmatch.h>
#include <ctype.h>
@@ -969,19 +971,13 @@ int generate_entries(int fd)
*/
int Write_rules(char *rule_name)
{
- int fd;
- char udev_rule_file[PATH_MAX];
+ int fd = fileno(stdout);
- if (rule_name) {
- strncpy(udev_rule_file, rule_name, sizeof(udev_rule_file) - 6);
- udev_rule_file[sizeof(udev_rule_file) - 6] = '\0';
- strcat(udev_rule_file, ".temp");
- fd = creat(udev_rule_file,
- S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
- if (fd == -1)
- return 1;
- } else
- fd = 1;
+ if (rule_name)
+ fd = creat(rule_name, 0644);
+
+ if (!is_fd_valid(fd))
+ return 1;
/* write static invocation */
if (write(fd, udev_template_start, sizeof(udev_template_start) - 1) !=
@@ -993,15 +989,14 @@ int Write_rules(char *rule_name)
goto abort;
fsync(fd);
- if (rule_name) {
+ if (rule_name)
close(fd);
- rename(udev_rule_file, rule_name);
- }
+
return 0;
abort:
if (rule_name) {
close(fd);
- unlink(udev_rule_file);
+ unlink(rule_name);
}
return 1;
}