generator: Log to standard error by default 86/298486/2 accepted/tizen/unified/20230908.185301
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Thu, 7 Sep 2023 12:24:10 +0000 (14:24 +0200)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Thu, 7 Sep 2023 14:13:20 +0000 (16:13 +0200)
Additionally, prepend each log with program name.

Change-Id: I9fec53490de6d56268959f7517b24be1ceb7c593

packaging/isu.spec
src/systemd_generator/isu-generator

index 84353ad..dc2fe2f 100644 (file)
@@ -1,6 +1,6 @@
 Summary: Individual Service Upgrade support
 Name:    isu
-Version: 8.0.8
+Version: 8.0.9
 Release: 1
 Source0: %{name}-%{version}.tar.gz
 License: MIT
index e8607e7..d0f9653 100755 (executable)
@@ -9,17 +9,6 @@ RUNDIR="/run/isu"
 # Public key will be checked only if below variable is set
 #PUBKEY="/path/to/publickey.pem"
 
-if [ "$PUBKEY" -a ! -r "$PUBKEY" ]; then
-       echo "Public key specified but not readable: $PUBKEY"
-       exit 1
-fi
-
-if [ -z "$1" ]; then
-       echo "Please specify unitdir(s) as decribed in systemd.generator (1 or 3 arguments)"
-       exit 1
-fi
-UNITDIR="$1"
-
 MY_NAME=$(basename "$0")
 
 if [ "$MY_NAME" = "isu-system-generator" ]; then
@@ -35,6 +24,11 @@ else
        exit 1
 fi
 
+log()
+{
+       echo "$MY_NAME: $*" >&2
+}
+
 install_units()
 {
        local srv_path="$1"
@@ -72,6 +66,7 @@ EOF
        if ! mv "${new_srv_path}.tmp" "${new_srv_path}"; then
                mv "${confd}/isu.conf" "${confd}/isu.conf.revert" || :
        fi
+       log "Installed $INSTANCE service $srv_path for package $isu_pkg_name"
 
        return 0
 }
@@ -81,7 +76,7 @@ install_mount_unit()
        local isu_pkg_name="$1"
 
        if ! mkdir -p "$RUNDIR/$isu_pkg_name/rootfs"; then
-               echo "Unable to create directory to mount $isu_pkg_dir's rootfs - skipping ISU package"
+               log "Unable to create directory to mount $isu_pkg_dir's rootfs - skipping ISU package"
                return 1
        fi
 
@@ -89,7 +84,7 @@ install_mount_unit()
        if [ ! -r "$UNITDIR/$mount_unit" ]; then
 
                if ! test -r "$i"/rootfs.img; then
-                       echo "Can not access rootfs.img. Skipping $isu_pkg_name"
+                       log "Can not access rootfs.img. Skipping $isu_pkg_name"
                        return 1
                fi
 
@@ -107,8 +102,9 @@ Before=local-fs.target
 What=${PKGDIR}/${isu_pkg_name}/rootfs.img
 Where=${RUNDIR}/${isu_pkg_name}/rootfs
 EOF
-       mkdir -p "$UNITDIR/local-fs.target.wants"
-       ln -s "../$mount_unit" "$UNITDIR/local-fs.target.wants/"
+               mkdir -p "$UNITDIR/local-fs.target.wants"
+               ln -s "../$mount_unit" "$UNITDIR/local-fs.target.wants/"
+               log "Installed $UNITDIR/$mount_unit for package $isu_pkg_name"
 
        fi
 
@@ -127,22 +123,22 @@ isu_prepare_system()
        cksum_path="${cksum_sign_path%.sign}"
        if [ "$PUBKEY" ]; then
                if ! openssl dgst -sha256 -verify "$PUBKEY" -signature "$cksum_sign_path" "$cksum_path"; then
-                       echo "Public key verification failed for $cksum_path"
+                       log "Public key verification failed for $cksum_path"
                        return 1
                fi
-               echo "Public key verification succeeded for $isu_pkg_dir"
+               log "Public key verification succeeded for $isu_pkg_dir"
        fi
 
        if [ -s "$cksum_path" ]; then
                pushd "$isu_pkg_dir"
                if ! sha256sum -c --status "$cksum_path"; then
                        popd
-                       echo "Checksum verification failed for $isu_pkg_dir - skipping ISU package"
+                       log "Checksum verification failed for $isu_pkg_dir - skipping ISU package"
                        return 1
                fi
                popd
        else
-               echo "Missing or broken checksum file: $cksum_path - skipping ISU package"
+               log "Missing or broken checksum file: $cksum_path - skipping ISU package"
                return 1
        fi
 
@@ -161,7 +157,7 @@ isu_prepare()
        for srv_path in $(compgen -G "${isu_pkg_dir}/${ISU_SERVICES_DIR}"/*.service); do
 
                if ! test -r "$srv_path"; then
-                       echo "Service file $srv_path not readable. Skipping"
+                       log "Service file $srv_path not readable. Skipping"
                        continue
                fi
 
@@ -171,17 +167,30 @@ isu_prepare()
        for unit_path in $(compgen -G "${isu_pkg_dir}/${ISU_SERVICES_DIR}"/*.mount); do
 
                if ! test -r "$unit_path"; then
-                       echo "Unit file $unit_path not readable. Skipping"
+                       log "Unit file $unit_path not readable. Skipping"
                        continue
                fi
                cp -a "$unit_path" "$UNITDIR/"
        done
 }
 
-# assume isu packages are extracted
+
+# Entry point
+
+if [ "$PUBKEY" -a ! -r "$PUBKEY" ]; then
+       echo "Public key specified but not readable: $PUBKEY"
+       exit 1
+fi
+
+if [ -z "$1" ]; then
+       echo "Please specify unitdir(s) as decribed in systemd.generator (1 or 3 arguments)"
+       exit 1
+fi
+UNITDIR="$1"
+
 for i in "$PKGDIR"/*; do
        if ! test -d "$i" -a -r "$i"/isu.cfg; then
-               echo "Can not access essential ISU package data. Skipping $PKGDIR"
+               log "Can not access essential ISU package data. Skipping $PKGDIR"
                continue
        fi