The pane is the reference's window now: the big clock, the date and the
zone, then Date & Time | Time Zone | Clock.
Date & Time: "Set date & time automatically:" with the server
(pool.ntp.org by default) and "Apply Time Service"; a month calendar with
the weekday row and < > for the months (the chosen day pressed), a time
field with "Now", an analog clock drawn on Expose and once a minute, and
"Set Date and Time". Both root actions run in the su(1) terminal the
program already uses: dtsystemsettings -set-time EPOCH and -set-ntp on|off
SERVER. Below: "To set date and time formats, use Language & Region." and
a button that opens that pane.
Clock: the bar's clock -- shown or not, 24-hour, seconds, weekday, date --
written to ~/.dt/clock ("show=", "format="), which dtbar reads at its next
minute (measured: format=%H:%M leaves "07:49" in the bar).
McdeSys has the system side: mcde_sys_ntp_get/set (NetBSD: ntpd=YES in
rc.conf, the pool line of ntp.conf, /etc/rc.d/ntpd start/stop; Linux:
timedatectl set-ntp and timesyncd.conf) and mcde_sys_time_set
(settimeofday(2), root).
Measured under Xvfb: the three tabs render
(docs/screenshots/leopard/System-Preferences-Date-and-Time-mcde.png,
...-Time-Zone-mcde.png, ...-Clock-mcde.png); the Clock tab writes
"show=1" and "format=%a %e %b %H:%M" to ~/.dt/clock, and dtbar with that
file shows the chosen format.
Not run: the root paths (this session has no root, and setting the
development host's clock or switching its NTP on is a hazard). The tests
the task asks for -- ntpd=YES in /etc/rc.conf, ntpd running, date(1)
changed -- belong in the test VM; the commands they use are the two above.
439 lines
16 KiB
C
439 lines
16 KiB
C
/*
|
|
* McdeSys.h -- MCDE's layer between the desktop and the operating system
|
|
*
|
|
* Copyright (c) 2026 The Makronix project. GNU LGPL 2.0 or later, as CDE.
|
|
*
|
|
* Programs of MCDE (the System Preferences first) change the system only
|
|
* through these functions; each operating system has one backend in
|
|
* lib/McdeSys/<system>.c that does it the system's own way (on NetBSD:
|
|
* useradd(8), /etc/rc.conf, ifconfig(8), wpa_supplicant(8) ...). See
|
|
* ext/src/mcde/AGENTS.md, "The philosophy".
|
|
*
|
|
* C99 and POSIX only. Every function returns MCDE_SYS_OK or a negative
|
|
* McdeSysStatus; on failure, mcde_sys_error() gives a sentence for the user.
|
|
* Functions that change the system need the privileges the backend documents
|
|
* (today: root); they do not raise privileges themselves.
|
|
*
|
|
* Status: lib/McdeSys implements mcde_sys_backend, mcde_sys_error,
|
|
* mcde_sys_info, mcde_sys_power, mcde_sys_interfaces, the sound, Bluetooth,
|
|
* battery, time zone, sharing, the network browser, disks, backup,
|
|
* user and software update functions (common.c, net.c, sound.c, users.c,
|
|
* netbsd.c, linux.c); the network setup and the host name setter are the
|
|
* contract still.
|
|
*/
|
|
|
|
#ifndef _Mcde_McdeSys_h
|
|
#define _Mcde_McdeSys_h
|
|
|
|
#include <stddef.h>
|
|
#include <sys/types.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
typedef enum {
|
|
MCDE_SYS_OK = 0,
|
|
MCDE_SYS_ENOTSUP = -1, /* this backend cannot do it */
|
|
MCDE_SYS_EPERM = -2, /* not allowed (privileges) */
|
|
MCDE_SYS_EINVAL = -3, /* a bad argument (name, address ...) */
|
|
MCDE_SYS_EEXIST = -4, /* it exists already */
|
|
MCDE_SYS_ENOENT = -5, /* it does not exist */
|
|
MCDE_SYS_EFAIL = -6 /* the system tool failed; see mcde_sys_error() */
|
|
} McdeSysStatus;
|
|
|
|
/* the name of the backend ("netbsd", "linux"), for the About box and logs */
|
|
const char *mcde_sys_backend(void);
|
|
/* the last failure as a sentence for the user; never NULL */
|
|
const char *mcde_sys_error(void);
|
|
|
|
/*
|
|
* Users and groups
|
|
*/
|
|
typedef struct {
|
|
char login[32]; /* [a-z_][a-z0-9_-]*, as useradd(8) takes it */
|
|
char fullname[128];
|
|
uid_t uid;
|
|
int admin; /* may administer the computer (wheel/sudo) */
|
|
} McdeSysUser;
|
|
|
|
/* the people who use this computer (not the system accounts); returns count */
|
|
int mcde_sys_users(McdeSysUser *users, size_t max);
|
|
int mcde_sys_user_add(const McdeSysUser *user, const char *password);
|
|
int mcde_sys_user_delete(const char *login, int keep_home);
|
|
int mcde_sys_user_set_password(const char *login, const char *password);
|
|
int mcde_sys_user_set_admin(const char *login, int admin);
|
|
|
|
/*
|
|
* Network
|
|
*/
|
|
typedef enum {
|
|
MCDE_NET_WIRED,
|
|
MCDE_NET_WIFI,
|
|
MCDE_NET_OTHER
|
|
} McdeSysNetKind;
|
|
|
|
typedef struct {
|
|
char name[32]; /* the system's name: wm0, urtwn0, eth0 */
|
|
McdeSysNetKind kind;
|
|
int up; /* has an address */
|
|
char address[64]; /* the IPv4 or IPv6 address, or "" */
|
|
char ssid[33]; /* Wi-Fi: the network joined, or "" */
|
|
} McdeSysInterface;
|
|
|
|
typedef struct {
|
|
char ssid[33];
|
|
int signal; /* 0..100 */
|
|
int secured;
|
|
} McdeSysWifi;
|
|
|
|
/* the network interfaces; returns count */
|
|
int mcde_sys_interfaces(McdeSysInterface *ifs, size_t max);
|
|
|
|
/* how an interface gets its IPv4 and IPv6 addresses (System Settings >
|
|
* Network, TCP/IP); docs/reference/netconfig.txt in the Makronix tree */
|
|
typedef enum {
|
|
MCDE_IPV4_DHCP, /* Using DHCP */
|
|
MCDE_IPV4_DHCP_MANUAL, /* Using DHCP with manual address */
|
|
MCDE_IPV4_MANUAL, /* Manually */
|
|
MCDE_IPV4_OFF
|
|
} McdeSysIpv4;
|
|
|
|
typedef enum {
|
|
MCDE_IPV6_AUTO, /* Automatically (router advertisements) */
|
|
MCDE_IPV6_MANUAL,
|
|
MCDE_IPV6_OFF
|
|
} McdeSysIpv6;
|
|
|
|
#define MCDE_NET_DNS_MAX 4
|
|
|
|
typedef struct {
|
|
/* configured: what the interface gets at every start */
|
|
McdeSysIpv4 ipv4;
|
|
char address[48]; /* IPv4, dotted */
|
|
char netmask[48]; /* dotted: 255.255.255.0 */
|
|
char router[48];
|
|
char clientid[64]; /* the DHCP client ID, or "" */
|
|
McdeSysIpv6 ipv6;
|
|
char address6[64];
|
|
int prefix6; /* 1..128 */
|
|
char dns[MCDE_NET_DNS_MAX][48]; /* the DNS servers */
|
|
int ndns;
|
|
char search[MCDE_NET_DNS_MAX][96]; /* search domains */
|
|
int nsearch;
|
|
/* now, read only: what the interface has at this moment */
|
|
char cur_address[48];
|
|
char cur_netmask[48];
|
|
char cur_router[48];
|
|
char cur_address6[64];
|
|
int cur_prefix6;
|
|
char cur_dns[MCDE_NET_DNS_MAX][48];
|
|
int ncur_dns;
|
|
char mac[24]; /* the Ethernet ID, aa:bb:cc:dd:ee:ff */
|
|
int mtu;
|
|
char media[64]; /* "1000baseT full-duplex", or "" */
|
|
} McdeSysNetConfig;
|
|
|
|
/* the settings of IFNAME, configured and current */
|
|
int mcde_sys_net_config(const char *ifname, McdeSysNetConfig *config);
|
|
/* configure IFNAME (the "configured" part of CONFIG), now and at every
|
|
* start; the administrator only */
|
|
int mcde_sys_net_configure(const char *ifname,
|
|
const McdeSysNetConfig *config);
|
|
/* ask the DHCP server again (Renew DHCP Lease) */
|
|
int mcde_sys_net_renew(const char *ifname);
|
|
/* the Wi-Fi networks in reach; returns count */
|
|
int mcde_sys_wifi_scan(const char *ifname, McdeSysWifi *nets, size_t max);
|
|
/* join a Wi-Fi network, now and at every boot; passphrase NULL if open */
|
|
int mcde_sys_wifi_join(const char *ifname, const char *ssid,
|
|
const char *passphrase);
|
|
|
|
/*
|
|
* The computer
|
|
*/
|
|
typedef struct {
|
|
char system[64]; /* "Makronix", "Debian GNU/Linux" */
|
|
char version[64]; /* "0.99.9", "14" */
|
|
char kernel[128]; /* "NetBSD 11.99.9", "Linux 7.1.3" */
|
|
char model[128]; /* the machine, as the firmware names it */
|
|
char cpu[128]; /* the processor, as it names itself */
|
|
int cpus; /* processors online */
|
|
unsigned long long memory; /* bytes */
|
|
char disk[128]; /* the startup disk: the device of / */
|
|
unsigned long long diskSize; /* bytes of /, and free of them */
|
|
unsigned long long diskFree;
|
|
char hostname[256];
|
|
} McdeSysInfo;
|
|
|
|
/* what the About box shows; fields the system cannot tell are "" or 0 */
|
|
int mcde_sys_info(McdeSysInfo *info);
|
|
|
|
typedef enum {
|
|
MCDE_POWER_SLEEP,
|
|
MCDE_POWER_RESTART,
|
|
MCDE_POWER_SHUTDOWN
|
|
} McdeSysPower;
|
|
|
|
/* sleep, restart or shut down the computer, the system's own way */
|
|
int mcde_sys_power(McdeSysPower what);
|
|
|
|
/*
|
|
* Sound: the volume of the default output, through the sound server where
|
|
* one runs (PulseAudio), else the system's mixer
|
|
*/
|
|
int mcde_sys_volume_get(int *percent, int *muted); /* 0..100 */
|
|
int mcde_sys_volume_set(int percent);
|
|
int mcde_sys_volume_mute(int muted);
|
|
/* play a sound file (WAV) on the default output and return at once, the
|
|
* player left running on its own; MCDE_SYS_ENOTSUP when there is none */
|
|
int mcde_sys_sound_play(const char *file);
|
|
|
|
/*
|
|
* Bluetooth: the first controller
|
|
*/
|
|
typedef struct {
|
|
int present; /* there is a controller */
|
|
int on; /* it is powered */
|
|
char name[32]; /* the system's name of it: ubt0, hci0 */
|
|
} McdeSysBluetooth;
|
|
|
|
int mcde_sys_bluetooth(McdeSysBluetooth *bt);
|
|
int mcde_sys_bluetooth_power(int on);
|
|
|
|
/*
|
|
* The battery: all batteries of the machine as one, and the mains
|
|
*/
|
|
typedef struct {
|
|
int present; /* there is a battery */
|
|
int percent; /* its charge, 0..100 */
|
|
int charging; /* it is being charged */
|
|
int ac; /* the machine runs on mains power */
|
|
int minutes; /* until it is empty, -1 when not known or
|
|
* not running on it */
|
|
} McdeSysBattery;
|
|
|
|
int mcde_sys_battery(McdeSysBattery *bat);
|
|
|
|
/*
|
|
* The keyboard: is the one attached a Macintosh keyboard (Command left of
|
|
* the space bar, Option left of that)? 1 yes, 0 no. dtkeys makes the key
|
|
* left of the space bar the Command key (Mod4) on every keyboard.
|
|
*/
|
|
int mcde_sys_keyboard_is_mac(void);
|
|
|
|
/*
|
|
* Software update: the system and the packages, from the update source the
|
|
* system names (NetBSD: the URL in /etc/makronix/update, a release directory
|
|
* as build.sh makes it)
|
|
*/
|
|
typedef struct {
|
|
char current[64]; /* the version running */
|
|
char available[64]; /* the version the source has, or "" */
|
|
int packages; /* packages with a newer version, or -1: unknown */
|
|
char source[256]; /* where it looks, for the user */
|
|
char note[256]; /* a sentence for the user, or "" */
|
|
} McdeSysUpdate;
|
|
|
|
int mcde_sys_update_check(McdeSysUpdate *u);
|
|
/* bring the system and the packages up to what the source has (root) */
|
|
int mcde_sys_update_apply(void);
|
|
|
|
int mcde_sys_hostname_get(char *name, size_t len);
|
|
int mcde_sys_hostname_set(const char *name); /* now and at boot */
|
|
/*
|
|
* Sharing: the services that let others in, and the folders they share.
|
|
* SMB (Samba), NFS and AFP (netatalk) share the same folders; AppleTalk is
|
|
* netatalk's atalkd, the old network itself (NetBSD's kernel has it).
|
|
*/
|
|
typedef enum {
|
|
MCDE_SHARE_SSH, /* remote login */
|
|
MCDE_SHARE_SMB, /* file sharing for Windows and others */
|
|
MCDE_SHARE_NFS, /* file sharing for Unix */
|
|
MCDE_SHARE_AFP, /* file sharing by AFP over TCP */
|
|
MCDE_SHARE_APPLETALK, /* the AppleTalk network (atalkd, papd) */
|
|
MCDE_SHARE_COUNT
|
|
} McdeSysShareService;
|
|
|
|
typedef struct {
|
|
int installed; /* the server is there */
|
|
int enabled; /* it starts at boot */
|
|
int running; /* it runs now */
|
|
} McdeSysServiceState;
|
|
|
|
int mcde_sys_service_state(McdeSysShareService s, McdeSysServiceState *st);
|
|
/* on or off, now and at every boot (root) */
|
|
int mcde_sys_service_set(McdeSysShareService s, int on);
|
|
|
|
#define MCDE_SYS_SHARE_LEN 256
|
|
/* the shared folders (/etc/mcde-shares); how many */
|
|
int mcde_sys_shares(char (*paths)[MCDE_SYS_SHARE_LEN], size_t max);
|
|
/* share these folders by SMB, NFS and AFP: the list and the servers'
|
|
* configuration, which running servers read again (root) */
|
|
int mcde_sys_shares_set(char (*paths)[MCDE_SYS_SHARE_LEN], size_t n);
|
|
|
|
/*
|
|
* The network: the computers that announce what they offer (DNS-SD,
|
|
* multicast DNS), and connecting to what they share. A computer's kinds
|
|
* are bits of McdeSysNetKinds.
|
|
*/
|
|
enum {
|
|
MCDE_NET_HAS_SMB = 1 << 0, /* _smb._tcp */
|
|
MCDE_NET_HAS_AFP = 1 << 1, /* _afpovertcp._tcp */
|
|
MCDE_NET_HAS_NFS = 1 << 2, /* _nfs._tcp */
|
|
MCDE_NET_HAS_SSH = 1 << 3, /* _ssh._tcp or _sftp-ssh._tcp */
|
|
MCDE_NET_HAS_ANY = 1 << 4 /* _workstation._tcp, nothing shared */
|
|
};
|
|
|
|
typedef struct {
|
|
char name[128]; /* as it calls itself: "kitt" */
|
|
char host[256]; /* its address: "kitt.local" */
|
|
int kinds; /* MCDE_NET_HAS_* */
|
|
} McdeSysNetHost;
|
|
|
|
/* the computers found within about TIMEOUT_MS; how many */
|
|
int mcde_sys_net_browse(McdeSysNetHost *hosts, size_t max, int timeout_ms);
|
|
/* what HOST shares: NFS exports (showmount) or SMB shares (smbclient -L);
|
|
* KIND is MCDE_NET_HAS_NFS or _SMB; how many */
|
|
int mcde_sys_net_shares(const char *host, int kind, char (*names)[256],
|
|
size_t max);
|
|
/* connect URL -- sftp://[user@]host[/path], nfs://host/path,
|
|
* afp://[user@]host/volume -- to the folder MOUNTPOINT, which must exist;
|
|
* PASSWORD may be NULL */
|
|
int mcde_sys_net_mount(const char *url, const char *mountpoint,
|
|
const char *password);
|
|
/* disconnect what is mounted at MOUNTPOINT */
|
|
int mcde_sys_net_unmount(const char *mountpoint);
|
|
|
|
/*
|
|
* Disks: the drives and their partitions (NetBSD: wedges), where they are
|
|
* mounted, and what can be done to them. NAME is the system's: wd0, dk1,
|
|
* sd0 / nvme0n1, sda1. Changing a disk needs root.
|
|
*/
|
|
typedef struct {
|
|
char name[32];
|
|
char parent[32]; /* the drive of a partition; "" for a drive */
|
|
char model[96]; /* a drive's model, or "" */
|
|
char fstype[32]; /* ffs, msdos, ext2fs, swap, cd9660 ...; "" */
|
|
char label[96]; /* the partition's or volume's name, or "" */
|
|
unsigned long long bytes;
|
|
int removable; /* a stick, a card, a CD */
|
|
int system; /* holds / or swap: never erased */
|
|
char mountpoint[256]; /* where mounted, or "" */
|
|
unsigned long long used, avail; /* when mounted */
|
|
} McdeSysDisk;
|
|
|
|
/* the drives, each followed by its partitions; how many */
|
|
int mcde_sys_disks(McdeSysDisk *d, size_t max);
|
|
/* mount partition NAME on /media/LABEL (made); where, into MOUNTPOINT */
|
|
int mcde_sys_disk_mount(const char *name, char *mountpoint, size_t len);
|
|
int mcde_sys_disk_unmount(const char *name);
|
|
/* check partition NAME without changing it (fsck -n); its report into LOG */
|
|
int mcde_sys_disk_check(const char *name, char *log, size_t len);
|
|
/* erase the whole drive NAME: one partition, FSTYPE ("ffs", "msdos";
|
|
* Linux also "ext4") named LABEL; the new partition's name into PART.
|
|
* Refused for a drive with a system partition or one that is mounted. */
|
|
int mcde_sys_disk_erase(const char *name, const char *fstype,
|
|
const char *label, char *part, size_t len);
|
|
|
|
/*
|
|
* The permissions of the system's files: compared with the list the system
|
|
* keeps of how they should be, and set back to it (REPAIR, root). What
|
|
* differs -- or what was set back -- goes into LOG, a line each; how many
|
|
* lines. NetBSD: mtree(8) against /etc/mtree/set.* (every installed set).
|
|
*/
|
|
int mcde_sys_permissions(int repair, char *log, size_t len);
|
|
|
|
/*
|
|
* Backup: the whole system, every hour, to a disk of its own, by BorgBackup
|
|
* -- encrypted (repokey-blake2), deduplicated; kept are, unless set
|
|
* otherwise, 24 hourly, 30 daily, 52 weekly and every monthly state, and
|
|
* when the disk's free space falls below a share (10 %), the oldest are
|
|
* deleted until it is back. Setting up, running, listing and restoring
|
|
* need root.
|
|
*/
|
|
typedef struct {
|
|
int configured; /* a disk and a repository are set up */
|
|
int enabled; /* it runs every hour */
|
|
char disk[32]; /* the partition it backs up to */
|
|
char repo[512]; /* the repository on it */
|
|
long long last; /* the last backup's time (time_t), or 0 */
|
|
char result[256]; /* how the last one ended */
|
|
/* how many are kept (-1: every one); and the free space below which
|
|
* the oldest backups are deleted, in percent of the disk */
|
|
int keepHourly, keepDaily, keepWeekly, keepMonthly;
|
|
int minFree;
|
|
} McdeSysBackup;
|
|
|
|
typedef struct {
|
|
char name[128];
|
|
char time[32]; /* "2026-11-11T14:00:03" */
|
|
} McdeSysBackupArchive;
|
|
|
|
int mcde_sys_backup_get(McdeSysBackup *b);
|
|
/* make PARTITION (mounted, or mountable) the backup disk: a repository on
|
|
* it, encrypted with PASSPHRASE, which is kept for the hourly runs */
|
|
int mcde_sys_backup_setup(const char *partition, const char *passphrase);
|
|
int mcde_sys_backup_enable(int on);
|
|
/* how many are kept and the free space to hold, from B (root) */
|
|
int mcde_sys_backup_policy(const McdeSysBackup *b);
|
|
/* one backup now (the hourly run does this); borg's report into LOG */
|
|
int mcde_sys_backup_run(char *log, size_t len);
|
|
/* the backups there are, oldest first; how many */
|
|
int mcde_sys_backup_archives(McdeSysBackupArchive *a, size_t max);
|
|
/* PATH (absolute, as it was) of backup ARCHIVE, into the folder DEST */
|
|
int mcde_sys_backup_restore(const char *archive, const char *path,
|
|
const char *dest);
|
|
|
|
/*
|
|
* A process: the command line it was started with, as one line a shell
|
|
* reads back (each argument in single quotes). For the front panel, which
|
|
* keeps a running program to start it again.
|
|
*/
|
|
int mcde_sys_process_command(pid_t pid, char *buf, size_t len);
|
|
/* 1 when the process is stopped (SIGSTOP, a debugger) or a zombie, 0 when
|
|
* it runs, -1 when it cannot be asked. The Force Quit dialog of dtbar
|
|
* marks the first kind "(not responding)". */
|
|
int mcde_sys_process_stopped(pid_t pid);
|
|
|
|
/*
|
|
* A file's comment and its lock, as the Info window of the file manager
|
|
* shows them. The comment is an extended attribute in the user namespace
|
|
* (user.mcde.comment on Linux, mcde.comment in EXTATTR_NAMESPACE_USER on
|
|
* NetBSD); an empty TEXT removes it; MCDE_SYS_ENOTSUP when the file system
|
|
* has no extended attributes. The lock is the immutable flag
|
|
* (FS_IMMUTABLE_FL on Linux, chflags(2) UF_IMMUTABLE on NetBSD).
|
|
*/
|
|
int mcde_sys_file_comment_get(const char *path, char *buf, size_t len);
|
|
int mcde_sys_file_comment_set(const char *path, const char *text);
|
|
int mcde_sys_file_locked_get(const char *path, int *locked);
|
|
int mcde_sys_file_locked_set(const char *path, int locked);
|
|
|
|
/*
|
|
* The time: the system's time service (NetBSD's ntpd from the base system
|
|
* through rc.conf and ntp.conf, on Linux systemd-timesyncd through
|
|
* timedatectl(1)), and the clock itself (settimeofday(2), root only).
|
|
*/
|
|
int mcde_sys_ntp_get(int *on, char *server, size_t len);
|
|
int mcde_sys_ntp_set(int on, const char *server);
|
|
int mcde_sys_time_set(time_t when);
|
|
|
|
/*
|
|
* The time zone: names as the tz database has them ("Europe/Lisbon").
|
|
* /etc/localtime is a symbolic link into /usr/share/zoneinfo on NetBSD and
|
|
* on Linux alike (sysinst sets it so: src/usr.sbin/sysinst/util.c); the
|
|
* zones offered are the ones of zone1970.tab.
|
|
*/
|
|
#define MCDE_SYS_ZONE_LEN 64
|
|
/* the zone in use, "UTC" when none is set */
|
|
int mcde_sys_timezone_get(char *zone, size_t len);
|
|
/* up to MAX zones, sorted; how many */
|
|
int mcde_sys_timezones(char (*zones)[MCDE_SYS_ZONE_LEN], size_t max);
|
|
/* now and at boot (root); a running program sees it at its next tzset(3) */
|
|
int mcde_sys_timezone_set(const char *zone);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* _Mcde_McdeSys_h */
|