- Taken with a few minor changes from systemd's hostnamed.c,
- copyright 2011 Lennart Poettering.
-
- See the SMBIOS Specification 2.7.1 section 7.4.1 for
- details about the values listed here:
-
- http://www.dmtf.org/sites/default/files/standards/documents/DSP0134_2.7.1.pdf
-
-
- if (g_file_get_contents ("/sys/class/dmi/id/chassis_type", &filebuf, NULL, NULL)) {
- switch (g_ascii_strtoull (filebuf, NULL, 10)) {
- case 0x3:
- case 0x4:
- case 0x5:
- case 0x6:
- case 0x7:
- ret = g_strdup ("computer-desktop");
- goto out;
- case 0x9:
- case 0xA:
- case 0xE:
- ret = g_strdup ("computer-laptop");
- goto out;
- case 0x11:
- case 0x17:
- case 0x1C:
- case 0x1D:
- ret = g_strdup ("computer-server");
- goto out;
+ unsigned int i;
+
+ for(; i < G_N_ELEMENTS(server_archs); i++)
+ if(strcasestr(arch, server_archs[i]))
+ return TRUE;
+
+ return FALSE;
+}
+
+gboolean up_native_is_laptop() {
+
+ struct apm_power_info bstate;
+ struct sensordev acpiac;
+
+ if (up_native_get_sensordev("acpiac0", &acpiac))
+ return TRUE;
+
+ if (-1 == ioctl(up_apm_get_fd(), APM_IOC_GETPOWER, &bstate))
+ g_error("ioctl on apm fd failed : %s", g_strerror(errno));
+
+ return bstate.ac_state != APM_AC_UNKNOWN;
+}
+
+int up_apm_get_fd() {
+
+ static int apm_fd = 0;
+
+ if(apm_fd == 0) {
+
+ g_debug("apm_fd is not initialized yet, opening");
+
+ /* open /dev/apm */
+ if((apm_fd = open("/dev/apm", O_RDONLY)) == -1) {
+ if(errno != ENXIO && errno != ENOENT)
+ g_error("cannot open device file");