Репозитории ALT
S: | 2.8.0-alt2 |
5.1: | 2.0.5-alt4 |
4.1: | 2.0.5-alt3 |
4.0: | 2.0.5-alt2 |
3.0: | 2.0.2-alt1 |
Группа :: Система/Серверы
Пакет: nut
Главная Изменения Спек Патчи Sources Загрузить Gear Bugs and FR Repocop
Патч: nut-2.0.5-alt-upsdrvctl-list.patch
Скачать
Скачать
--- nut-2.0.5/drivers/upsdrvctl.c.orig 2006-11-08 05:08:45 +0300
+++ nut-2.0.5/drivers/upsdrvctl.c 2007-03-25 05:39:26 +0400
@@ -276,6 +276,52 @@ static void start_driver(const ups_t *up
forkexec(dfn, argv, ups);
}
+static void list_driver(const ups_t *ups)
+{
+ char dfn[SMALLBUF];
+ int ret;
+ struct stat fs;
+
+ snprintf(dfn, sizeof(dfn), "%s/%s", driverpath, ups->driver);
+ ret = stat(dfn, &fs);
+
+ if (ret < 0)
+ upslogx(LOG_ERR, "stat: %s: %m", dfn);
+ else
+ puts (dfn);
+}
+
+/* list user-selected driver */
+static void list_one_driver(const char *upsname)
+{
+ ups_t *tmp = upstable;
+
+ if (!tmp)
+ fatalx("Error: no UPS definitions found in ups.conf!\n");
+
+ while (tmp) {
+ if (!strcmp(tmp->upsname, upsname)) {
+ list_driver(tmp);
+ return;
+ }
+
+ tmp = tmp->next;
+ }
+
+ fatalx("UPS %s not found in ups.conf", upsname);
+}
+
+/* walk ups table and list drivers */
+static void list_all_drivers(void)
+{
+ ups_t *tmp = upstable;
+
+ while (tmp) {
+ list_driver(tmp);
+ tmp = tmp->next;
+ }
+}
+
static void help(const char *progname)
{
printf("Starts and stops UPS drivers via ups.conf.\n\n");
@@ -286,6 +332,8 @@ static void help(const char *progname)
printf(" -t testing mode - prints actions without doing them\n");
printf(" -u <user> drivers started will switch from root to <user>\n");
printf(" -D raise debugging level\n");
+ printf(" list list all UPS drivers in ups.conf\n");
+ printf(" list <ups> only list driver for UPS <ups>\n");
printf(" start start all UPS drivers in ups.conf\n");
printf(" start <ups> only start driver for UPS <ups>\n");
printf(" stop stop all UPS drivers in ups.conf\n");
@@ -457,6 +505,9 @@ int main(int argc, char **argv)
if (!strcmp(argv[0], "shutdown"))
command = &shutdown_driver;
+ if (!strcmp(argv[0], "list"))
+ command = &list_driver;
+
if (!command)
fatalx("Error: unrecognized command [%s]", argv[0]);
@@ -466,6 +517,15 @@ int main(int argc, char **argv)
read_upsconf();
+ if (command == &list_driver) {
+ if (argc == 1)
+ list_all_drivers();
+ else
+ list_one_driver(argv[1]);
+
+ exit(EXIT_SUCCESS);
+ }
+
if (argc == 1)
send_all_drivers(command);
else