소스 검색

Ticket 583 - dirsrv fails to start on reboot due to /var/run/dirsrv permissions

Bug Description:  On Fedora, after a reboot the ownership/permissions can change
                  for /var/lock/dirsrv & /var/run/dirsrv.  This is because we
                  were not removing the old /etc/tmpfiles.d/dirsrv-INSTANCE.conf
                  file.  So if an existing tmpfile existed, it would not be updated
                  when creating a new instance.

Fix Description:  When removing an instance, we were using the wrong tmpfile name -
                  it was missing ".conf" extension.  This has been corrected.  Also,
                  when creating an instance, we now check for and delete the old
                  tmpfile.

https://fedorahosted.org/389/ticket/583

Reviewed by: nkinder(Thanks!)
Mark Reynolds 12 년 전
부모
커밋
febd0dbeab
1개의 변경된 파일41개의 추가작업 그리고 39개의 파일을 삭제
  1. 41 39
      ldap/admin/src/scripts/DSCreate.pm.in

+ 41 - 39
ldap/admin/src/scripts/DSCreate.pm.in

@@ -1040,48 +1040,50 @@ sub updateTmpfilesDotD {
     # if tmpfiles.d is not available, do nothing
     if ($dir and -d $dir) {
         my $filename = "$dir/@package_name@-$inf->{slapd}->{ServerIdentifier}.conf";
-        if (! -f $filename) {
-            debug(3, "Creating $filename\n");
-            my $username = "";
-            my $groupname = "";
-            my $conffile = "$inf->{slapd}->{config_dir}/dse.ldif";
-            # use the owner:group from the dse.ldif for the instance
-            if (-f $conffile) {
-                my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
-                    $atime,$mtime,$ctime,$blksize,$blocks)
-                    = stat(_);
-                $username = getpwuid($uid);
-                if (!$username) {
-                    debug(1, "Error: could not get username from uid $uid\n");
-                }
-                $groupname = getgrgid($gid);
+        if (-f $filename) {
+            debug(3, "Removing the old tmpfile: $filename\n");
+            if (!unlink($filename)){
+                debug(1, "Can not delete old tmpfile $filename ($!)\n");
+                return();
             }
-            # else, see if we were passed in values to use
+        }
+        debug(3, "Creating $filename\n");
+        my $username = "";
+        my $groupname = "";
+        my $conffile = "$inf->{slapd}->{config_dir}/dse.ldif";
+        # use the owner:group from the dse.ldif for the instance
+        if (-f $conffile) {
+            my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
+                $atime,$mtime,$ctime,$blksize,$blocks)
+                = stat(_);
+            $username = getpwuid($uid);
             if (!$username) {
-                $username = $inf->{General}->{SuiteSpotUserID};
-            }
-            if (!$groupname) {
-                if (defined($inf->{General}->{SuiteSpotGroup})) {
-                    $groupname = $inf->{General}->{SuiteSpotGroup};
-                } else { # $groupname
-                    $groupname = "-"; # use default
-                }
+                debug(1, "Error: could not get username from uid $uid\n");
             }
-
-            my $parent = dirname($inf->{slapd}->{lock_dir});
-            if (!open(DOTDFILE, ">$filename")) {
-                return ( [ 'error_creating_file', $filename, $! ] );
+            $groupname = getgrgid($gid);
+        }
+        # else, see if we were passed in values to use
+        if (!$username) {
+            $username = $inf->{General}->{SuiteSpotUserID};
+        }
+        if (!$groupname) {
+            if (defined($inf->{General}->{SuiteSpotGroup})) {
+                $groupname = $inf->{General}->{SuiteSpotGroup};
+            } else { # $groupname
+                $groupname = "-"; # use default
             }
-            # Type Path          Mode UID  GID  Age
-            # d    /var/run/user 0755 root root 10d
-            # we don't use age
-            print DOTDFILE "d $inf->{slapd}->{run_dir} 0770 $username $groupname\n";
-            print DOTDFILE "d $parent 0770 $username $groupname\n";
-            print DOTDFILE "d $inf->{slapd}->{lock_dir} 0770 $username $groupname\n";
-            close DOTDFILE;
-        } else {
-            debug(3, "$filename exists - skipping\n");
         }
+        my $parent = dirname($inf->{slapd}->{lock_dir});
+        if (!open(DOTDFILE, ">$filename")) {
+            return ( [ 'error_creating_file', $filename, $! ] );
+        }
+        # Type Path          Mode UID  GID  Age
+        # d    /var/run/user 0755 root root 10d
+        # we don't use age
+        print DOTDFILE "d $inf->{slapd}->{run_dir} 0770 $username $groupname\n";
+        print DOTDFILE "d $parent 0770 $username $groupname\n";
+        print DOTDFILE "d $inf->{slapd}->{lock_dir} 0770 $username $groupname\n";
+        close DOTDFILE;
     } else {
         debug(3, "no tmpfiles.d - skipping\n");
     }
@@ -1381,8 +1383,8 @@ sub removeDSInstance {
     }
 
     my $tmpfilesdir = "@with_tmpfiles_d@";
-    my $tmpfilesname = "$tmpfilesdir/@package_name@-$inst";
-    if ($tmpfilesdir and -d $tmpfilesdir and -f $tmpfilesname) {
+    my $tmpfilesname = "$tmpfilesdir/@package_name@-$inst.conf";
+    if ($tmpfilesdir && -d $tmpfilesdir && -f $tmpfilesname) {
         my $rc = unlink($tmpfilesname);
         if ( 0 == $rc )
         {