aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.config-device1
-rw-r--r--.config-linux1
-rw-r--r--.config-mac1
-rw-r--r--Android.bp2
-rw-r--r--android/device/generated/config.h2
-rw-r--r--android/device/generated/flags.h34
-rw-r--r--android/device/generated/globals.h12
-rw-r--r--android/device/generated/help.h2
-rw-r--r--android/device/generated/newtoys.h1
-rw-r--r--android/linux/generated/config.h2
-rw-r--r--android/linux/generated/flags.h34
-rw-r--r--android/linux/generated/globals.h12
-rw-r--r--android/linux/generated/help.h2
-rw-r--r--android/linux/generated/newtoys.h1
-rw-r--r--android/mac/generated/config.h2
-rw-r--r--android/mac/generated/flags.h34
-rw-r--r--android/mac/generated/globals.h12
-rw-r--r--android/mac/generated/help.h2
-rw-r--r--android/mac/generated/newtoys.h1
-rw-r--r--lib/lib.h1
-rw-r--r--lib/portability.h1
-rw-r--r--lib/xwrap.c13
-rw-r--r--toys/other/hwclock.c60
-rw-r--r--toys/pending/rtcwake.c134
24 files changed, 321 insertions, 46 deletions
diff --git a/.config-device b/.config-device
index 883ea020..bef57849 100644
--- a/.config-device
+++ b/.config-device
@@ -260,6 +260,7 @@ CONFIG_RMDIR=y
CONFIG_RMMOD=y
CONFIG_RM=y
# CONFIG_ROUTE is not set
+CONFIG_RTCWAKE=y
CONFIG_RUNCON=y
CONFIG_SED=y
CONFIG_SENDEVENT=y
diff --git a/.config-linux b/.config-linux
index 3dda7493..17a63fe9 100644
--- a/.config-linux
+++ b/.config-linux
@@ -254,6 +254,7 @@ CONFIG_RMDIR=y
# CONFIG_RMMOD is not set
CONFIG_RM=y
# CONFIG_ROUTE is not set
+# CONFIG_RTCWAKE is not set
# CONFIG_RUNCON is not set
CONFIG_SED=y
# CONFIG_SENDEVENT is not set
diff --git a/.config-mac b/.config-mac
index cebd9275..3580f68a 100644
--- a/.config-mac
+++ b/.config-mac
@@ -254,6 +254,7 @@ CONFIG_RMDIR=y
# CONFIG_RMMOD is not set
CONFIG_RM=y
# CONFIG_ROUTE is not set
+# CONFIG_RTCWAKE is not set
# CONFIG_RUNCON is not set
CONFIG_SED=y
# CONFIG_SENDEVENT is not set
diff --git a/Android.bp b/Android.bp
index 9a0cab9f..226fef28 100644
--- a/Android.bp
+++ b/Android.bp
@@ -264,6 +264,7 @@ cc_defaults {
"toys/pending/modprobe.c",
"toys/pending/more.c",
"toys/pending/readelf.c",
+ "toys/pending/rtcwake.c",
"toys/pending/stty.c",
"toys/pending/traceroute.c",
"toys/pending/vi.c",
@@ -414,6 +415,7 @@ cc_defaults {
"rm",
"rmdir",
"rmmod",
+ "rtcwake",
"runcon",
"sed",
"sendevent",
diff --git a/android/device/generated/config.h b/android/device/generated/config.h
index 4c0fc103..227673aa 100644
--- a/android/device/generated/config.h
+++ b/android/device/generated/config.h
@@ -494,6 +494,8 @@
#define USE_RM(...) __VA_ARGS__
#define CFG_ROUTE 0
#define USE_ROUTE(...)
+#define CFG_RTCWAKE 1
+#define USE_RTCWAKE(...) __VA_ARGS__
#define CFG_RUNCON 1
#define USE_RUNCON(...) __VA_ARGS__
#define CFG_SED 1
diff --git a/android/device/generated/flags.h b/android/device/generated/flags.h
index 4bbeadab..3b63c79d 100644
--- a/android/device/generated/flags.h
+++ b/android/device/generated/flags.h
@@ -2469,6 +2469,24 @@
#undef FLAG_n
#endif
+// rtcwake (list-modes);(auto)a(device)d:(local)l(mode)m:(seconds)s#(time)t#(utc)u(verbose)v[!alu] (list-modes);(auto)a(device)d:(local)l(mode)m:(seconds)s#(time)t#(utc)u(verbose)v[!alu]
+#undef OPTSTR_rtcwake
+#define OPTSTR_rtcwake "(list-modes);(auto)a(device)d:(local)l(mode)m:(seconds)s#(time)t#(utc)u(verbose)v[!alu]"
+#ifdef CLEANUP_rtcwake
+#undef CLEANUP_rtcwake
+#undef FOR_rtcwake
+#undef FLAG_v
+#undef FLAG_u
+#undef FLAG_t
+#undef FLAG_s
+#undef FLAG_m
+#undef FLAG_l
+#undef FLAG_d
+#undef FLAG_a
+#undef FLAG_auto
+#undef FLAG_list_modes
+#endif
+
// runcon <2 <2
#undef OPTSTR_runcon
#define OPTSTR_runcon "<2"
@@ -5528,6 +5546,22 @@
#define FLAG_n (FORCED_FLAG<<2)
#endif
+#ifdef FOR_rtcwake
+#ifndef TT
+#define TT this.rtcwake
+#endif
+#define FLAG_v (1<<0)
+#define FLAG_u (1<<1)
+#define FLAG_t (1<<2)
+#define FLAG_s (1<<3)
+#define FLAG_m (1<<4)
+#define FLAG_l (1<<5)
+#define FLAG_d (1<<6)
+#define FLAG_a (1<<7)
+#define FLAG_auto (1<<8)
+#define FLAG_list_modes (1<<9)
+#endif
+
#ifdef FOR_runcon
#ifndef TT
#define TT this.runcon
diff --git a/android/device/generated/globals.h b/android/device/generated/globals.h
index d51c5855..00d6ed7c 100644
--- a/android/device/generated/globals.h
+++ b/android/device/generated/globals.h
@@ -277,8 +277,6 @@ struct hexedit_data {
struct hwclock_data {
char *f;
-
- int utc;
};
// toys/other/ionice.c
@@ -806,6 +804,15 @@ struct route_data {
char *family;
};
+// toys/pending/rtcwake.c
+
+struct rtcwake_data {
+ long long t, s;
+ char *m, *d;
+
+ struct rtc_wkalrm alarm;
+};
+
// toys/pending/sh.c
struct sh_data {
@@ -1599,6 +1606,7 @@ extern union global_union {
struct openvt_data openvt;
struct readelf_data readelf;
struct route_data route;
+ struct rtcwake_data rtcwake;
struct sh_data sh;
struct stty_data stty;
struct sulogin_data sulogin;
diff --git a/android/device/generated/help.h b/android/device/generated/help.h
index b196253a..461559b3 100644
--- a/android/device/generated/help.h
+++ b/android/device/generated/help.h
@@ -358,6 +358,8 @@
#define HELP_sh "usage: sh [-c command] [script]\n\nCommand shell. Runs a shell script, or reads input interactively\nand responds to it.\n\n-c command line to execute\n-i interactive mode (default when STDIN is a tty)"
+#define HELP_rtcwake "usage: rtcwake [-aluv] [-d FILE] [-m MODE] [-s SECS] [-t UNIX]\n\nEnter the given sleep state until the given time.\n\n-a RTC uses time specified in /etc/adjtime\n-d FILE Device to use (default /dev/rtc)\n-l RTC uses local time\n-m Mode (--list-modes to see those supported by your kernel):\n disable Cancel current alarm\n freeze Freeze processes, idle processors\n disk S4: suspend to disk\n mem S3: suspend to RAM\n no Don't suspend, just set wakeup time\n off S5: power off\n on Don't suspend, poll RTC for alarm\n show Don't suspend, just show current alarm\n standby S1: default\n-s SECS Wake SECS seconds from now\n-t UNIX Wake UNIX seconds from epoch\n-u RTC uses UTC\n-v Verbose"
+
#define HELP_route "usage: route [-ne] [-A [46]] [add|del TARGET [OPTIONS]]\n\nDisplay, add or delete network routes in the \"Forwarding Information Base\".\n\n-n Show numerical addresses (no DNS lookups)\n-e display netstat fields\n\nRouting means sending packets out a network interface to an address.\nThe kernel can tell where to send packets one hop away by examining each\ninterface's address and netmask, so the most common use of this command\nis to identify a \"gateway\" that forwards other traffic.\n\nAssigning an address to an interface automatically creates an appropriate\nnetwork route (\"ifconfig eth0 10.0.2.15/8\" does \"route add 10.0.0.0/8 eth0\"\nfor you), although some devices (such as loopback) won't show it in the\ntable. For machines more than one hop away, you need to specify a gateway\n(ala \"route add default gw 10.0.2.2\").\n\nThe address \"default\" is a wildcard address (0.0.0.0/0) matching all\npackets without a more specific route.\n\nAvailable OPTIONS include:\nreject - blocking route (force match failure)\ndev NAME - force packets out this interface (ala \"eth0\")\nnetmask - old way of saying things like ADDR/24\ngw ADDR - forward packets to gateway ADDR"
#define HELP_readelf "usage: readelf [-adehlnSs] [-p SECTION] [-x SECTION] [file...]\n\nDisplays information about ELF files.\n\n-a Equivalent to -dhlnSs\n-d Show dynamic section\n-e Headers (equivalent to -hlS)\n-h Show ELF header\n-l Show program headers\n-n Show notes\n-p S Dump strings found in named/numbered section\n-S Show section headers\n-s Show symbol tables (.dynsym and .symtab)\n-x S Hex dump of named/numbered section\n\n--dyn-syms Show just .dynsym symbol table"
diff --git a/android/device/generated/newtoys.h b/android/device/generated/newtoys.h
index df5bd6f4..276ca3ac 100644
--- a/android/device/generated/newtoys.h
+++ b/android/device/generated/newtoys.h
@@ -219,6 +219,7 @@ USE_RM(NEWTOY(rm, "fiRrv[-fi]", TOYFLAG_BIN))
USE_RMDIR(NEWTOY(rmdir, "<1(ignore-fail-on-non-empty)p", TOYFLAG_BIN))
USE_RMMOD(NEWTOY(rmmod, "<1wf", TOYFLAG_SBIN|TOYFLAG_NEEDROOT))
USE_ROUTE(NEWTOY(route, "?neA:", TOYFLAG_BIN))
+USE_RTCWAKE(NEWTOY(rtcwake, "(list-modes);(auto)a(device)d:(local)l(mode)m:(seconds)s#(time)t#(utc)u(verbose)v[!alu]", TOYFLAG_USR|TOYFLAG_BIN))
USE_RUNCON(NEWTOY(runcon, "<2", TOYFLAG_USR|TOYFLAG_SBIN))
USE_SED(NEWTOY(sed, "(help)(version)e*f*i:;nErz(null-data)[+Er]", TOYFLAG_BIN|TOYFLAG_LOCALE|TOYFLAG_NOHELP))
USE_SENDEVENT(NEWTOY(sendevent, "<4>4", TOYFLAG_USR|TOYFLAG_SBIN))
diff --git a/android/linux/generated/config.h b/android/linux/generated/config.h
index d69f7c42..790d1437 100644
--- a/android/linux/generated/config.h
+++ b/android/linux/generated/config.h
@@ -482,6 +482,8 @@
#define USE_RM(...) __VA_ARGS__
#define CFG_ROUTE 0
#define USE_ROUTE(...)
+#define CFG_RTCWAKE 0
+#define USE_RTCWAKE(...)
#define CFG_RUNCON 0
#define USE_RUNCON(...)
#define CFG_SED 1
diff --git a/android/linux/generated/flags.h b/android/linux/generated/flags.h
index e27ff338..e3486f87 100644
--- a/android/linux/generated/flags.h
+++ b/android/linux/generated/flags.h
@@ -2469,6 +2469,24 @@
#undef FLAG_n
#endif
+// rtcwake (list-modes);(auto)a(device)d:(local)l(mode)m:(seconds)s#(time)t#(utc)u(verbose)v[!alu]
+#undef OPTSTR_rtcwake
+#define OPTSTR_rtcwake "(list-modes);(auto)a(device)d:(local)l(mode)m:(seconds)s#(time)t#(utc)u(verbose)v[!alu]"
+#ifdef CLEANUP_rtcwake
+#undef CLEANUP_rtcwake
+#undef FOR_rtcwake
+#undef FLAG_v
+#undef FLAG_u
+#undef FLAG_t
+#undef FLAG_s
+#undef FLAG_m
+#undef FLAG_l
+#undef FLAG_d
+#undef FLAG_a
+#undef FLAG_auto
+#undef FLAG_list_modes
+#endif
+
// runcon <2
#undef OPTSTR_runcon
#define OPTSTR_runcon "<2"
@@ -5528,6 +5546,22 @@
#define FLAG_n (FORCED_FLAG<<2)
#endif
+#ifdef FOR_rtcwake
+#ifndef TT
+#define TT this.rtcwake
+#endif
+#define FLAG_v (FORCED_FLAG<<0)
+#define FLAG_u (FORCED_FLAG<<1)
+#define FLAG_t (FORCED_FLAG<<2)
+#define FLAG_s (FORCED_FLAG<<3)
+#define FLAG_m (FORCED_FLAG<<4)
+#define FLAG_l (FORCED_FLAG<<5)
+#define FLAG_d (FORCED_FLAG<<6)
+#define FLAG_a (FORCED_FLAG<<7)
+#define FLAG_auto (FORCED_FLAG<<8)
+#define FLAG_list_modes (FORCED_FLAG<<9)
+#endif
+
#ifdef FOR_runcon
#ifndef TT
#define TT this.runcon
diff --git a/android/linux/generated/globals.h b/android/linux/generated/globals.h
index d51c5855..00d6ed7c 100644
--- a/android/linux/generated/globals.h
+++ b/android/linux/generated/globals.h
@@ -277,8 +277,6 @@ struct hexedit_data {
struct hwclock_data {
char *f;
-
- int utc;
};
// toys/other/ionice.c
@@ -806,6 +804,15 @@ struct route_data {
char *family;
};
+// toys/pending/rtcwake.c
+
+struct rtcwake_data {
+ long long t, s;
+ char *m, *d;
+
+ struct rtc_wkalrm alarm;
+};
+
// toys/pending/sh.c
struct sh_data {
@@ -1599,6 +1606,7 @@ extern union global_union {
struct openvt_data openvt;
struct readelf_data readelf;
struct route_data route;
+ struct rtcwake_data rtcwake;
struct sh_data sh;
struct stty_data stty;
struct sulogin_data sulogin;
diff --git a/android/linux/generated/help.h b/android/linux/generated/help.h
index 4f091427..d5f21e6f 100644
--- a/android/linux/generated/help.h
+++ b/android/linux/generated/help.h
@@ -360,6 +360,8 @@
#define HELP_sh "usage: sh [-c command] [script]\n\nCommand shell. Runs a shell script, or reads input interactively\nand responds to it.\n\n-c command line to execute\n-i interactive mode (default when STDIN is a tty)"
+#define HELP_rtcwake "usage: rtcwake [-aluv] [-d FILE] [-m MODE] [-s SECS] [-t UNIX]\n\nEnter the given sleep state until the given time.\n\n-a RTC uses time specified in /etc/adjtime\n-d FILE Device to use (default /dev/rtc)\n-l RTC uses local time\n-m Mode (--list-modes to see those supported by your kernel):\n disable Cancel current alarm\n freeze Freeze processes, idle processors\n disk S4: suspend to disk\n mem S3: suspend to RAM\n no Don't suspend, just set wakeup time\n off S5: power off\n on Don't suspend, poll RTC for alarm\n show Don't suspend, just show current alarm\n standby S1: default\n-s SECS Wake SECS seconds from now\n-t UNIX Wake UNIX seconds from epoch\n-u RTC uses UTC\n-v Verbose"
+
#define HELP_route "usage: route [-ne] [-A [46]] [add|del TARGET [OPTIONS]]\n\nDisplay, add or delete network routes in the \"Forwarding Information Base\".\n\n-n Show numerical addresses (no DNS lookups)\n-e display netstat fields\n\nRouting means sending packets out a network interface to an address.\nThe kernel can tell where to send packets one hop away by examining each\ninterface's address and netmask, so the most common use of this command\nis to identify a \"gateway\" that forwards other traffic.\n\nAssigning an address to an interface automatically creates an appropriate\nnetwork route (\"ifconfig eth0 10.0.2.15/8\" does \"route add 10.0.0.0/8 eth0\"\nfor you), although some devices (such as loopback) won't show it in the\ntable. For machines more than one hop away, you need to specify a gateway\n(ala \"route add default gw 10.0.2.2\").\n\nThe address \"default\" is a wildcard address (0.0.0.0/0) matching all\npackets without a more specific route.\n\nAvailable OPTIONS include:\nreject - blocking route (force match failure)\ndev NAME - force packets out this interface (ala \"eth0\")\nnetmask - old way of saying things like ADDR/24\ngw ADDR - forward packets to gateway ADDR"
#define HELP_readelf "usage: readelf [-adehlnSs] [-p SECTION] [-x SECTION] [file...]\n\nDisplays information about ELF files.\n\n-a Equivalent to -dhlnSs\n-d Show dynamic section\n-e Headers (equivalent to -hlS)\n-h Show ELF header\n-l Show program headers\n-n Show notes\n-p S Dump strings found in named/numbered section\n-S Show section headers\n-s Show symbol tables (.dynsym and .symtab)\n-x S Hex dump of named/numbered section\n\n--dyn-syms Show just .dynsym symbol table"
diff --git a/android/linux/generated/newtoys.h b/android/linux/generated/newtoys.h
index df5bd6f4..276ca3ac 100644
--- a/android/linux/generated/newtoys.h
+++ b/android/linux/generated/newtoys.h
@@ -219,6 +219,7 @@ USE_RM(NEWTOY(rm, "fiRrv[-fi]", TOYFLAG_BIN))
USE_RMDIR(NEWTOY(rmdir, "<1(ignore-fail-on-non-empty)p", TOYFLAG_BIN))
USE_RMMOD(NEWTOY(rmmod, "<1wf", TOYFLAG_SBIN|TOYFLAG_NEEDROOT))
USE_ROUTE(NEWTOY(route, "?neA:", TOYFLAG_BIN))
+USE_RTCWAKE(NEWTOY(rtcwake, "(list-modes);(auto)a(device)d:(local)l(mode)m:(seconds)s#(time)t#(utc)u(verbose)v[!alu]", TOYFLAG_USR|TOYFLAG_BIN))
USE_RUNCON(NEWTOY(runcon, "<2", TOYFLAG_USR|TOYFLAG_SBIN))
USE_SED(NEWTOY(sed, "(help)(version)e*f*i:;nErz(null-data)[+Er]", TOYFLAG_BIN|TOYFLAG_LOCALE|TOYFLAG_NOHELP))
USE_SENDEVENT(NEWTOY(sendevent, "<4>4", TOYFLAG_USR|TOYFLAG_SBIN))
diff --git a/android/mac/generated/config.h b/android/mac/generated/config.h
index f9363323..11b69996 100644
--- a/android/mac/generated/config.h
+++ b/android/mac/generated/config.h
@@ -482,6 +482,8 @@
#define USE_RM(...) __VA_ARGS__
#define CFG_ROUTE 0
#define USE_ROUTE(...)
+#define CFG_RTCWAKE 0
+#define USE_RTCWAKE(...)
#define CFG_RUNCON 0
#define USE_RUNCON(...)
#define CFG_SED 1
diff --git a/android/mac/generated/flags.h b/android/mac/generated/flags.h
index eee3209f..f30fb95c 100644
--- a/android/mac/generated/flags.h
+++ b/android/mac/generated/flags.h
@@ -2469,6 +2469,24 @@
#undef FLAG_n
#endif
+// rtcwake (list-modes);(auto)a(device)d:(local)l(mode)m:(seconds)s#(time)t#(utc)u(verbose)v[!alu]
+#undef OPTSTR_rtcwake
+#define OPTSTR_rtcwake "(list-modes);(auto)a(device)d:(local)l(mode)m:(seconds)s#(time)t#(utc)u(verbose)v[!alu]"
+#ifdef CLEANUP_rtcwake
+#undef CLEANUP_rtcwake
+#undef FOR_rtcwake
+#undef FLAG_v
+#undef FLAG_u
+#undef FLAG_t
+#undef FLAG_s
+#undef FLAG_m
+#undef FLAG_l
+#undef FLAG_d
+#undef FLAG_a
+#undef FLAG_auto
+#undef FLAG_list_modes
+#endif
+
// runcon <2
#undef OPTSTR_runcon
#define OPTSTR_runcon "<2"
@@ -5528,6 +5546,22 @@
#define FLAG_n (FORCED_FLAG<<2)
#endif
+#ifdef FOR_rtcwake
+#ifndef TT
+#define TT this.rtcwake
+#endif
+#define FLAG_v (FORCED_FLAG<<0)
+#define FLAG_u (FORCED_FLAG<<1)
+#define FLAG_t (FORCED_FLAG<<2)
+#define FLAG_s (FORCED_FLAG<<3)
+#define FLAG_m (FORCED_FLAG<<4)
+#define FLAG_l (FORCED_FLAG<<5)
+#define FLAG_d (FORCED_FLAG<<6)
+#define FLAG_a (FORCED_FLAG<<7)
+#define FLAG_auto (FORCED_FLAG<<8)
+#define FLAG_list_modes (FORCED_FLAG<<9)
+#endif
+
#ifdef FOR_runcon
#ifndef TT
#define TT this.runcon
diff --git a/android/mac/generated/globals.h b/android/mac/generated/globals.h
index d51c5855..00d6ed7c 100644
--- a/android/mac/generated/globals.h
+++ b/android/mac/generated/globals.h
@@ -277,8 +277,6 @@ struct hexedit_data {
struct hwclock_data {
char *f;
-
- int utc;
};
// toys/other/ionice.c
@@ -806,6 +804,15 @@ struct route_data {
char *family;
};
+// toys/pending/rtcwake.c
+
+struct rtcwake_data {
+ long long t, s;
+ char *m, *d;
+
+ struct rtc_wkalrm alarm;
+};
+
// toys/pending/sh.c
struct sh_data {
@@ -1599,6 +1606,7 @@ extern union global_union {
struct openvt_data openvt;
struct readelf_data readelf;
struct route_data route;
+ struct rtcwake_data rtcwake;
struct sh_data sh;
struct stty_data stty;
struct sulogin_data sulogin;
diff --git a/android/mac/generated/help.h b/android/mac/generated/help.h
index 4f091427..d5f21e6f 100644
--- a/android/mac/generated/help.h
+++ b/android/mac/generated/help.h
@@ -360,6 +360,8 @@
#define HELP_sh "usage: sh [-c command] [script]\n\nCommand shell. Runs a shell script, or reads input interactively\nand responds to it.\n\n-c command line to execute\n-i interactive mode (default when STDIN is a tty)"
+#define HELP_rtcwake "usage: rtcwake [-aluv] [-d FILE] [-m MODE] [-s SECS] [-t UNIX]\n\nEnter the given sleep state until the given time.\n\n-a RTC uses time specified in /etc/adjtime\n-d FILE Device to use (default /dev/rtc)\n-l RTC uses local time\n-m Mode (--list-modes to see those supported by your kernel):\n disable Cancel current alarm\n freeze Freeze processes, idle processors\n disk S4: suspend to disk\n mem S3: suspend to RAM\n no Don't suspend, just set wakeup time\n off S5: power off\n on Don't suspend, poll RTC for alarm\n show Don't suspend, just show current alarm\n standby S1: default\n-s SECS Wake SECS seconds from now\n-t UNIX Wake UNIX seconds from epoch\n-u RTC uses UTC\n-v Verbose"
+
#define HELP_route "usage: route [-ne] [-A [46]] [add|del TARGET [OPTIONS]]\n\nDisplay, add or delete network routes in the \"Forwarding Information Base\".\n\n-n Show numerical addresses (no DNS lookups)\n-e display netstat fields\n\nRouting means sending packets out a network interface to an address.\nThe kernel can tell where to send packets one hop away by examining each\ninterface's address and netmask, so the most common use of this command\nis to identify a \"gateway\" that forwards other traffic.\n\nAssigning an address to an interface automatically creates an appropriate\nnetwork route (\"ifconfig eth0 10.0.2.15/8\" does \"route add 10.0.0.0/8 eth0\"\nfor you), although some devices (such as loopback) won't show it in the\ntable. For machines more than one hop away, you need to specify a gateway\n(ala \"route add default gw 10.0.2.2\").\n\nThe address \"default\" is a wildcard address (0.0.0.0/0) matching all\npackets without a more specific route.\n\nAvailable OPTIONS include:\nreject - blocking route (force match failure)\ndev NAME - force packets out this interface (ala \"eth0\")\nnetmask - old way of saying things like ADDR/24\ngw ADDR - forward packets to gateway ADDR"
#define HELP_readelf "usage: readelf [-adehlnSs] [-p SECTION] [-x SECTION] [file...]\n\nDisplays information about ELF files.\n\n-a Equivalent to -dhlnSs\n-d Show dynamic section\n-e Headers (equivalent to -hlS)\n-h Show ELF header\n-l Show program headers\n-n Show notes\n-p S Dump strings found in named/numbered section\n-S Show section headers\n-s Show symbol tables (.dynsym and .symtab)\n-x S Hex dump of named/numbered section\n\n--dyn-syms Show just .dynsym symbol table"
diff --git a/android/mac/generated/newtoys.h b/android/mac/generated/newtoys.h
index df5bd6f4..276ca3ac 100644
--- a/android/mac/generated/newtoys.h
+++ b/android/mac/generated/newtoys.h
@@ -219,6 +219,7 @@ USE_RM(NEWTOY(rm, "fiRrv[-fi]", TOYFLAG_BIN))
USE_RMDIR(NEWTOY(rmdir, "<1(ignore-fail-on-non-empty)p", TOYFLAG_BIN))
USE_RMMOD(NEWTOY(rmmod, "<1wf", TOYFLAG_SBIN|TOYFLAG_NEEDROOT))
USE_ROUTE(NEWTOY(route, "?neA:", TOYFLAG_BIN))
+USE_RTCWAKE(NEWTOY(rtcwake, "(list-modes);(auto)a(device)d:(local)l(mode)m:(seconds)s#(time)t#(utc)u(verbose)v[!alu]", TOYFLAG_USR|TOYFLAG_BIN))
USE_RUNCON(NEWTOY(runcon, "<2", TOYFLAG_USR|TOYFLAG_SBIN))
USE_SED(NEWTOY(sed, "(help)(version)e*f*i:;nErz(null-data)[+Er]", TOYFLAG_BIN|TOYFLAG_LOCALE|TOYFLAG_NOHELP))
USE_SENDEVENT(NEWTOY(sendevent, "<4>4", TOYFLAG_USR|TOYFLAG_SBIN))
diff --git a/lib/lib.h b/lib/lib.h
index 66b39d67..c528f190 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -188,6 +188,7 @@ void xsignal(int signal, void *handler);
time_t xvali_date(struct tm *tm, char *str);
void xparsedate(char *str, time_t *t, unsigned *nano, int endian);
char *xgetline(FILE *fp, int *len);
+time_t xmktime(struct tm *tm, int utc);
// lib.c
void verror_msg(char *msg, int err, va_list va);
diff --git a/lib/portability.h b/lib/portability.h
index acc32fd4..41128958 100644
--- a/lib/portability.h
+++ b/lib/portability.h
@@ -175,6 +175,7 @@ void *memmem(const void *haystack, size_t haystack_length,
// Linux headers not listed by POSIX or LSB
#include <sys/mount.h>
#ifdef __linux__
+#include <linux/rtc.h>
#include <sys/statfs.h>
#include <sys/swap.h>
#include <sys/sysinfo.h>
diff --git a/lib/xwrap.c b/lib/xwrap.c
index 555fbd5e..5f18f295 100644
--- a/lib/xwrap.c
+++ b/lib/xwrap.c
@@ -1077,3 +1077,16 @@ char *xgetline(FILE *fp, int *len)
return new;
}
+
+time_t xmktime(struct tm *tm, int utc)
+{
+ char *old_tz = utc ? xtzset("UTC0") : 0;
+ time_t result;
+
+ if ((result = mktime(tm)) < 0) error_exit("mktime");
+ if (utc) {
+ free(xtzset(old_tz));
+ free(old_tz);
+ }
+ return result;
+}
diff --git a/toys/other/hwclock.c b/toys/other/hwclock.c
index 52e71604..5ab308df 100644
--- a/toys/other/hwclock.c
+++ b/toys/other/hwclock.c
@@ -25,12 +25,9 @@ config HWCLOCK
#define FOR_hwclock
#include "toys.h"
-#include <linux/rtc.h>
GLOBALS(
char *f;
-
- int utc;
)
static int rtc_find(struct dirtree* node)
@@ -61,23 +58,17 @@ void hwclock_main()
struct timezone tzone;
struct timeval timeval;
struct tm tm;
- time_t time;
- int fd = -1;
+ int fd = -1, utc;
- // check for Grenich Mean Time
- if (toys.optflags & FLAG_u) TT.utc = 1;
+ if (FLAG(u)) utc = 1;
+ else if (FLAG(l)) utc = 0;
else {
- FILE *fp;
- char *s = 0;
-
- for (fp = fopen("/etc/adjtime", "r");
- fp && getline(&s, (void *)toybuf, fp)>0;
- free(s), s = 0) TT.utc += !strncmp(s, "UTC", 3);
- if (fp) fclose(fp);
+ xreadfile("/etc/adjtime", toybuf, sizeof(toybuf));
+ utc = !!strstr(toybuf, "UTC");
}
- if (!(toys.optflags&FLAG_t)) {
- int w = toys.optflags & FLAG_w, flag = O_WRONLY*w;
+ if (!FLAG(t)) {
+ int flag = O_WRONLY*FLAG(w);
// Open /dev/rtc (if your system has no /dev/rtc symlink, search for it).
if (!TT.f && (fd = open("/dev/rtc", flag)) == -1) {
@@ -87,49 +78,38 @@ void hwclock_main()
if (fd == -1) fd = xopen(TT.f, flag);
// Get current time in seconds from rtc device. todo: get subsecond time
- if (!w) {
- char *s = s;
-
+ if (!FLAG(w)) {
xioctl(fd, RTC_RD_TIME, &tm);
- if (TT.utc) s = xtzset("UTC0");
- if ((time = mktime(&tm)) < 0) error_exit("mktime failed");
- if (TT.utc) {
- free(xtzset(s));
- free(s);
- }
+ timeval.tv_sec = xmktime(&tm, utc);
+ timeval.tv_usec = 0; // todo: fixit
}
}
- if (toys.optflags & (FLAG_w|FLAG_t)) {
+ if (FLAG(w) || FLAG(t)) {
if (gettimeofday(&timeval, 0)) perror_exit("gettimeofday failed");
- if (!(TT.utc ? gmtime_r : localtime_r)(&timeval.tv_sec, &tm))
- error_exit(TT.utc ? "gmtime_r failed" : "localtime_r failed");
+ if (!(utc ? gmtime_r : localtime_r)(&timeval.tv_sec, &tm))
+ error_exit(utc ? "gmtime_r failed" : "localtime_r failed");
}
- if (toys.optflags & FLAG_w) {
+ if (FLAG(w)) {
/* The value of tm_isdst is positive if daylight saving time is in effect,
* zero if it is not and negative if the information is not available.
* todo: so why isn't this negative...? */
tm.tm_isdst = 0;
xioctl(fd, RTC_SET_TIME, &tm);
- } else if (toys.optflags & FLAG_s) {
+ } else if (FLAG(s)) {
tzone.tz_minuteswest = timezone / 60 - 60 * daylight;
- timeval.tv_sec = time;
- timeval.tv_usec = 0; // todo: fixit
- } else if (toys.optflags & FLAG_t) {
+ } else if (FLAG(t)) {
// Adjust seconds for timezone and daylight saving time
// extern long timezone is defined in header sys/time.h
tzone.tz_minuteswest = timezone / 60;
if (tm.tm_isdst) tzone.tz_minuteswest -= 60;
- if (!TT.utc) timeval.tv_sec += tzone.tz_minuteswest * 60;
+ if (!utc) timeval.tv_sec += tzone.tz_minuteswest * 60;
} else {
- char *c = ctime(&time), *s = strrchr(c, '\n');
-
- if (s) *s = '\0';
- // TODO: implement this.
- xprintf("%s 0.000000 seconds\n", c);
+ strftime(toybuf, sizeof(toybuf), "%F %T%z", &tm);
+ xputs(toybuf);
}
- if (toys.optflags & (FLAG_t|FLAG_s)) {
+ if (FLAG(t) || FLAG(s)) {
tzone.tz_dsttime = 0;
if (settimeofday(&timeval, &tzone)) perror_exit("settimeofday failed");
}
diff --git a/toys/pending/rtcwake.c b/toys/pending/rtcwake.c
new file mode 100644
index 00000000..0929d51f
--- /dev/null
+++ b/toys/pending/rtcwake.c
@@ -0,0 +1,134 @@
+/* rtcwake.c - enter sleep state until given time.
+ *
+ * Copyright 2020 The Android Open Source Project
+
+USE_RTCWAKE(NEWTOY(rtcwake, "(list-modes);(auto)a(device)d:(local)l(mode)m:(seconds)s#(time)t#(utc)u(verbose)v[!alu]", TOYFLAG_USR|TOYFLAG_BIN))
+
+config RTCWAKE
+ bool "rtcwake"
+ default n
+ help
+ usage: rtcwake [-aluv] [-d FILE] [-m MODE] [-s SECS] [-t UNIX]
+
+ Enter the given sleep state until the given time.
+
+ -a RTC uses time specified in /etc/adjtime
+ -d FILE Device to use (default /dev/rtc)
+ -l RTC uses local time
+ -m Mode (--list-modes to see those supported by your kernel):
+ disable Cancel current alarm
+ freeze Freeze processes, idle processors
+ disk S4: suspend to disk
+ mem S3: suspend to RAM
+ no Don't suspend, just set wakeup time
+ off S5: power off
+ on Don't suspend, poll RTC for alarm
+ show Don't suspend, just show current alarm
+ standby S1: default
+ -s SECS Wake SECS seconds from now
+ -t UNIX Wake UNIX seconds from epoch
+ -u RTC uses UTC
+ -v Verbose
+*/
+
+#define FOR_rtcwake
+#include "toys.h"
+
+GLOBALS(
+ long long t, s;
+ char *m, *d;
+
+ struct rtc_wkalrm alarm;
+)
+
+void rtcwake_main(void)
+{
+ time_t now, rtc_now, then;
+ struct tm rtc_tm;
+ int fd, utc;
+
+ if (FLAG(list_modes)) {
+ xreadfile("/sys/power/state", toybuf, sizeof(toybuf));
+ printf("off no on disable show %s", toybuf);
+ return;
+ }
+
+ // util-linux defaults to "suspend", even though I don't have anything that
+ // supports that (testing everything from a ~2010 laptop to a 2019 desktop).
+ if (!TT.m) TT.m = "suspend";
+
+ if (FLAG(u)) utc = 1;
+ else if (FLAG(l)) utc = 0;
+ else {
+ xreadfile("/etc/adjtime", toybuf, sizeof(toybuf));
+ utc = !!strstr(toybuf, "UTC");
+ }
+ if (FLAG(v)) xprintf("RTC time: %s\n", utc ? "UTC" : "local");
+
+ if (!TT.d) TT.d = "/dev/rtc0";
+ if (FLAG(v)) xprintf("Device: %s\n", TT.d);
+ fd = xopen(TT.d, O_RDWR);
+
+ now = time(0);
+ xioctl(fd, RTC_RD_TIME, &rtc_tm);
+ rtc_now = xmktime(&rtc_tm, utc);
+ if (FLAG(v)) {
+ xprintf("System time:\t%lld / %s", (long long)now, ctime(&now));
+ xprintf("RTC time:\t%lld / %s", (long long)rtc_now, ctime(&rtc_now));
+ }
+
+ if (!strcmp(TT.m, "show")) { // Don't suspend, just show current alarm.
+ xioctl(fd, RTC_WKALM_RD, &TT.alarm);
+ if (!TT.alarm.enabled) xputs("alarm: off");
+ else {
+ if ((then = mktime((void *)&TT.alarm.time)) < 0) perror_exit("mktime");
+ xprintf("alarm: on %s", ctime(&then));
+ }
+ goto done;
+ } else if (!strcmp(TT.m, "disable")) { // Cancel current alarm.
+ xioctl(fd, RTC_WKALM_RD, &TT.alarm);
+ TT.alarm.enabled = 0;
+ xioctl(fd, RTC_WKALM_SET, &TT.alarm);
+ goto done;
+ }
+
+ if (FLAG(s)) {
+ then = rtc_now + TT.s + 1; // strace shows util-linux adds 1.
+ } else if (FLAG(t)) {
+ then = TT.t + (rtc_now - now);
+ if (then<=rtc_now) error_exit("rtc %lld >= %lld", (long long)rtc_now, TT.t);
+ } else help_exit("-m %s needs -s or -t", TT.m);
+ if (FLAG(v)) xprintf("Wake time:\t%lld / %s", (long long)then, ctime(&then));
+
+ if (!(utc ? gmtime_r : localtime_r)(&then, (void *)&TT.alarm.time))
+ error_exit(utc ? "gmtime_r failed" : "localtime_r failed");
+
+ TT.alarm.enabled = 1;
+ xioctl(fd, RTC_WKALM_SET, &TT.alarm);
+ sync();
+
+ xprintf("wakeup using \"%s\" from %s at %s", TT.m, TT.d, ctime(&then));
+ msleep(10);
+
+ if (!strcmp(TT.m, "no")) { // Don't suspend, just set wakeup time.
+ } else if (!strcmp(TT.m, "on")) { // Don't suspend, poll RTC for alarm.
+ unsigned long data = 0;
+
+ if (FLAG(v)) xputs("Reading RTC...");
+ while (!(data & RTC_AF)) {
+ if (read(fd, &data, sizeof(data)) != sizeof(data)) perror_exit("read");
+ if (FLAG(v)) xprintf("... %s: %lx\n", TT.d, data);
+ }
+ } else if (!strcmp(TT.m, "off")) {
+ xexec((char *[]){"poweroff", 0});
+ } else {
+ // Everything else lands here for one final step. The write will fail with
+ // EINVAL if the mode is not supported.
+ int fd = xopen("/sys/power/state", O_WRONLY);
+
+ xwrite(fd, TT.m, strlen(TT.m));
+ close(fd);
+ }
+done:
+ close(fd);
+}