Procházet zdrojové kódy

generic init.d: stat not portable. Issue #1815

The `stat` utility tends to vary across *nixes. This relies instead upon the
hopefully more portable `ls` and `cut` commands to determine ownership and
permission modes.
Paul Kilgo před 11 roky
rodič
revize
77e66ccede
2 změnil soubory, kde provedl 12 přidání a 10 odebrání
  1. 6 5
      extra/generic-init.d/celerybeat
  2. 6 5
      extra/generic-init.d/celeryd

+ 6 - 5
extra/generic-init.d/celerybeat

@@ -43,10 +43,11 @@ SCRIPT_NAME="$(basename "$SCRIPT_FILE")"
 # Make sure executable configuration script is owned by root
 _config_sanity() {
     local path="$1"
-    local owner=$(stat -Lr "$path" | awk '{print $5}')
-    local perm=$(stat -Lr "$path" | awk '{print $3}')
+    local owner=$(ls -ld "$path" | awk '{print $3}')
+    local iwgrp=$(ls -ld "$path" | cut -b 6)
+    local iwoth=$(ls -ld "$path" | cut -b 9)
 
-    if [ "$owner" != "0" ]; then
+    if [ "$(id -u $owner)" != "0" ]; then
         echo "Error: Config script '$path' must be owned by root!"
         echo
         echo "Resolution:"
@@ -58,7 +59,7 @@ _config_sanity() {
         exit 1
     fi
 
-    if [ "$(($perm & 02))" -ne 0 ]; then  # S_IWOTH
+    if [ "$iwoth" != "-" ]; then  # S_IWOTH
         echo "Error: Config script '$path' cannot be writable by others!"
         echo
         echo "Resolution:"
@@ -69,7 +70,7 @@ _config_sanity() {
         echo "    $ sudo chmod 640 '$path'"
         exit 1
     fi
-    if [ "$(($perm & 020))" -ne 0 ]; then  # S_IWGRP
+    if [ "$iwgrp" != "-" ]; then  # S_IWGRP
         echo "Error: Config script '$path' cannot be writable by group!"
         echo
         echo "Resolution:"

+ 6 - 5
extra/generic-init.d/celeryd

@@ -58,10 +58,11 @@ CELERY_DEFAULTS=${CELERY_DEFAULTS:-"/etc/default/${SCRIPT_NAME}"}
 # Make sure executable configuration script is owned by root
 _config_sanity() {
     local path="$1"
-    local owner=$(stat -Lr "$path" | awk '{print $5}')
-    local perm=$(stat -Lr "$path" | awk '{print $3}')
+    local owner=$(ls -ld "$path" | awk '{print $3}')
+    local iwgrp=$(ls -ld "$path" | cut -b 6)
+    local iwoth=$(ls -ld "$path" | cut -b 9)
 
-    if [ "$owner" != "0" ]; then
+    if [ "$(id -u $owner)" != "0" ]; then
         echo "Error: Config script '$path' must be owned by root!"
         echo
         echo "Resolution:"
@@ -73,7 +74,7 @@ _config_sanity() {
         exit 1
     fi
 
-    if [ "$(($perm & 02))" -ne 0 ]; then  # S_IWOTH
+    if [ "$iwoth" != "-" ]; then  # S_IWOTH
         echo "Error: Config script '$path' cannot be writable by others!"
         echo
         echo "Resolution:"
@@ -84,7 +85,7 @@ _config_sanity() {
         echo "    $ sudo chmod 640 '$path'"
         exit 1
     fi
-    if [ "$(($perm & 020))" -ne 0 ]; then  # S_IWGRP
+    if [ "$iwgrp" != "-" ]; then  # S_IWGRP
         echo "Error: Config script '$path' cannot be writable by group!"
         echo
         echo "Resolution:"