From: Mateusz Majewski Date: Fri, 4 Feb 2022 07:34:42 +0000 (+0100) Subject: packaging: only apply rule if file exists X-Git-Tag: submit/tizen_6.5/20220204.140020^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e070cd7854695fe5415b41e590b0529ee79ef73e;p=platform%2Fcore%2Fapi%2Fperipheral-io.git packaging: only apply rule if file exists Change-Id: I8b29a8ea266c98672080436854e9fe3c0ce44b5e --- diff --git a/packaging/apply-peripheral-io-perms b/packaging/apply-peripheral-io-perms new file mode 100644 index 0000000..6729982 --- /dev/null +++ b/packaging/apply-peripheral-io-perms @@ -0,0 +1,15 @@ +#!/bin/sh + +[ $# -lt 2 ] && exit 1 + +DIR="$1" +shift + +for FILE in "$@"; do + # Let's make sure that the file really exists. + [ -e "$DIR/$FILE" ] || continue + + chown root:priv_peripheralio "$DIR/$FILE" + chmod 0660 "$DIR/$FILE" + chsmack -a '*' "$DIR/$FILE" +done diff --git a/packaging/capi-system-peripheral-io.spec b/packaging/capi-system-peripheral-io.spec index 7c24610..1d35aee 100644 --- a/packaging/capi-system-peripheral-io.spec +++ b/packaging/capi-system-peripheral-io.spec @@ -8,6 +8,7 @@ Source0: %{name}-%{version}.tar.gz Source1: %{name}.manifest Source10: peripheral-io.udev.rules Source11: peripheral-io.tmpfiles.conf +Source12: apply-peripheral-io-perms #Conflicts: peripheral-bus BuildRequires: awk BuildRequires: cmake @@ -48,6 +49,7 @@ Tizen Peripheral Input & Output Test Programs (test) cp %{SOURCE1} ./%{name}.manifest cp %{SOURCE10} . cp %{SOURCE11} . +cp %{SOURCE12} . %build MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` @@ -59,6 +61,8 @@ mkdir -p %{buildroot}/usr/lib/tmpfiles.d install -m0644 peripheral-io.tmpfiles.conf %{buildroot}/usr/lib/tmpfiles.d/peripheral-io.conf mkdir -p %{buildroot}/usr/lib/udev/rules.d install -m0644 peripheral-io.udev.rules %{buildroot}/usr/lib/udev/rules.d/90-peripheral-io.rules +mkdir -p %{buildroot}/%{_libexecdir}/peripheral-io +install -m0755 apply-peripheral-io-perms %{buildroot}/%{_libexecdir}/peripheral-io/apply-peripheral-io-perms %post -p /sbin/ldconfig @@ -70,6 +74,7 @@ install -m0644 peripheral-io.udev.rules %{buildroot}/usr/lib/udev/rules.d/90-per %{_libdir}/lib%{name}.so* /usr/lib/tmpfiles.d/peripheral-io.conf /usr/lib/udev/rules.d/90-peripheral-io.rules +%{_libexecdir}/peripheral-io/apply-peripheral-io-perms %license LICENSE.APLv2 %files devel diff --git a/packaging/peripheral-io.udev.rules b/packaging/peripheral-io.udev.rules index 4d038b5..61de265 100644 --- a/packaging/peripheral-io.udev.rules +++ b/packaging/peripheral-io.udev.rules @@ -1,35 +1,11 @@ SUBSYSTEM=="gpio", KERNEL=="gpiochip[0-9]*", ACTION=="add",\ MODE="0660", OWNER="root", GROUP="priv_peripheralio", SECLABEL{smack}="*" -SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add",\ - RUN+="/bin/chown root:priv_peripheralio /sys%p/value",\ - RUN+="/bin/chmod 0660 /sys%p/value",\ - RUN+="/bin/chsmack -a * /sys%p/value" -SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add",\ - RUN+="/bin/chown root:priv_peripheralio /sys%p/direction",\ - RUN+="/bin/chmod 0660 /sys%p/direction",\ - RUN+="/bin/chsmack -a * /sys%p/direction" -SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add",\ - RUN+="/bin/chown root:priv_peripheralio /sys%p/edge",\ - RUN+="/bin/chmod 0660 /sys%p/edge",\ - RUN+="/bin/chsmack -a * /sys%p/edge" +SUBSYSTEM=="gpio", KERNEL=="gpio[0-9]*", ACTION=="add",\ + RUN+="/usr/libexec/peripheral-io/apply-udev-file /sys%p value direction edge" SUBSYSTEM=="pwm", KERNEL=="pwm*", ACTION=="change",\ - RUN+="/bin/chown root:priv_peripheralio /sys%p/%E{EXPORT}/period",\ - RUN+="/bin/chmod 0660 /sys%p/%E{EXPORT}/period",\ - RUN+="/bin/chsmack -a * /sys%p/%E{EXPORT}/period" -SUBSYSTEM=="pwm", KERNEL=="pwm*", ACTION=="change",\ - RUN+="/bin/chown root:priv_peripheralio /sys%p/%E{EXPORT}/duty_cycle",\ - RUN+="/bin/chmod 0660 /sys%p/%E{EXPORT}/duty_cycle",\ - RUN+="/bin/chsmack -a * /sys%p/%E{EXPORT}/duty_cycle" -SUBSYSTEM=="pwm", KERNEL=="pwm*", ACTION=="change",\ - RUN+="/bin/chown root:priv_peripheralio /sys%p/%E{EXPORT}/polarity",\ - RUN+="/bin/chmod 0660 /sys%p/%E{EXPORT}/polarity",\ - RUN+="/bin/chsmack -a * /sys%p/%E{EXPORT}/polarity" -SUBSYSTEM=="pwm", KERNEL=="pwm*", ACTION=="change",\ - RUN+="/bin/chown root:priv_peripheralio /sys%p/%E{EXPORT}/enable",\ - RUN+="/bin/chmod 0660 /sys%p/%E{EXPORT}/enable",\ - RUN+="/bin/chsmack -a * /sys%p/%E{EXPORT}/enable" + RUN+="/usr/libexec/peripheral-io/apply-udev-file /sys%p/%E{EXPORT} period duty_cycle polarity enable" SUBSYSTEM=="i2c-dev", KERNEL=="i2c-*", ACTION=="add", \ MODE="0660", OWNER="root", GROUP="priv_peripheralio", SECLABEL{smack}="*"