Files
mcde/lib/McdeSys/private.h
T
lotherk f4ec4a1da1 MCDE: the disk-removed warning through the kernel's device events (t0093)
A medium that is pulled while it is still mounted now gets the reference's
one-button "Disk Not Ejected" warning: Motif's error dialog, the device and
its stale mountpoint in the text, the Warning sound.  The desktop (dtwm,
WmMcdeDesktop.c) owns the event descriptor already; it reads each event,
asks what it says, and checks the mount table before it shows anything.

McdeSys:
- mcde_sys_disk_event_info() parses both shapes the read gives: Linux's
  uevent with its NULs turned into spaces ("remove@/... ACTION=remove
  DEVNAME=sdb1 ...") and NetBSD's "device-detach sd0"; 1 when the device
  went away, 0 for add/change/attach, -1 on bad arguments.
- mcde_sys_disk_detached(name, mountpoint, len): looks in the mount table
  for a partition of NAME (sdb takes sdb1, sd0 takes sd0a), copies the
  mountpoint and unmounts it the forced way -- "umount -l" on Linux,
  "umount -f" on NetBSD (disk_linux.c, disk_netbsd.c) -- but never what the
  computer runs from.  0 when nothing of NAME was mounted.
- test_disk_events.c: the uevent and drvctl shapes, add/change/attach,
  missing DEVNAME, the bad arguments.  make check: 8/8 PASS (the seven
  before and this one).

Measured under Xvfb :79 with a real ext4 loop mount at /tmp/opencode/mnt:
- start of dtwm with MCDE_DESK_TEST_DEVICE="remove@/... DEVNAME=loop0":
  log "desktop: loop0 (remove)", "umount: /tmp/opencode/mnt: must be
  superuser to unmount.", "desktop: loop0 was mounted at
  /tmp/opencode/mnt"; the dialog is 354x167 at (335,300), OK as the only
  button (docs/screenshots/leopard/Device-Removal-mcde.png).
- sudo umount /tmp/opencode/mnt, the same event again: log "desktop: loop0
  (remove)" and no "was mounted"; zero dialog windows -- a device that was
  put away stays quiet.
- make mcde-linux MCDE_DIRS="install lib/McdeSys programs/dtwm" exit=0;
  MCDE_DIRS=plist "mcde-plist-check: ok".

MCDE_DESK_TEST_DEVICE is the test hook: one event line through the same
handler a real event takes, without a kernel.  The NetBSD drvctl branch is
unchanged (t0272); the force unmount there is written for it but was not
run.  Still open in t0093: the Eject item in dtfile (Selected menu,
Command+E) and the qemu device_del test in a VM.
2026-11-16 13:56:06 +00:00

385 lines
15 KiB
C

/*
* private.h -- MCDE: what common.c and the backends of McdeSys share
*
* License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
*/
#ifndef _McdeSys_private_h
#define _McdeSys_private_h
#include <stddef.h>
#include <sys/types.h>
#include <Mcde/McdeSys.h>
/* the failure STATUS with its sentence for the user; returns STATUS */
int mcde_sys_fail(int status, const char *fmt, ...);
/* the sentences of the tool errors, set 1 of mcdesys.cat (text.c) */
#define MSG_NOT_THERE 1
#define MSG_CANNOT_START 2
#define MSG_TOOL_FAILED 3
#define MSG_NO_PIPE 4
#define MSG_NO_ANSWER 5
#define MSG_NO_MEMORY 6
#define MSG_NO_PROGRAM 7
#define MSG_NO_CONNECT_ANSWER 8
#define MSG_CANCELLED 9
/* netmount.c: the addresses, the shares and the tools that mount them */
#define MSG_NET_NO_HOST 10
#define MSG_NET_NO_SHOWMOUNT 11
#define MSG_NET_NO_SMBCLIENT 12
#define MSG_NET_NO_SHARE_LIST 13
#define MSG_NET_NO_ADDRESS 14
#define MSG_NET_BAD_PASSWORD 15
#define MSG_NET_NO_SSHFS 16
#define MSG_NET_NO_NFS 17
#define MSG_NET_NO_MOUNT_AFP 18
#define MSG_NET_SCHEME 19
#define MSG_NET_NO_FOLDER 20
#define MSG_NET_NO_UMOUNT 21
/* backup.c: the backup disk, the password, borg and the administrator */
#define MSG_BAK_WRITE 22
#define MSG_BAK_WRONG_DISK 23
#define MSG_BAK_EPERM_SETUP 24
#define MSG_BAK_EPERM_CHANGE 25
#define MSG_BAK_EPERM_SWITCH 26
#define MSG_BAK_EPERM_RUN 27
#define MSG_BAK_EPERM_LOOK 28
#define MSG_BAK_EPERM_RESTORE 29
#define MSG_BAK_NO_BORG 30
#define MSG_BAK_PASSWORD 31
#define MSG_BAK_NO_DISK_CHOOSE 32
#define MSG_BAK_BAD_NUMBERS 33
#define MSG_BAK_NO_CRONTAB 34
#define MSG_BAK_NO_DTBACKUP 35
#define MSG_BAK_NO_DISK 36
#define MSG_BAK_NOTHING 37
#define MSG_BAK_CD 38
/* sound.c: the sound server, a file and the player */
#define MSG_SND_NO_VOLUME 39
#define MSG_SND_NO_FILE 40
#define MSG_SND_NO_PLAYER 41
#define MSG_SND_CANNOT_START 42
/* printers.c: CUPS, the name of a printer and the mDNS browser */
#define MSG_PRN_NO_PLACE 43
#define MSG_PRN_NO_LPSTAT 44
#define MSG_PRN_NO_ANSWER 45
#define MSG_PRN_NO_NAME 46
#define MSG_PRN_NO_LPADMIN 47
#define MSG_PRN_DEFAULT_EPERM 48
#define MSG_PRN_DEFAULT_FAIL 49
#define MSG_PRN_BAD_NAME 50
#define MSG_PRN_ADD_EPERM 51
#define MSG_PRN_ADD_FAIL 52
#define MSG_PRN_REMOVE_EPERM 53
#define MSG_PRN_REMOVE_FAIL 54
#define MSG_PRN_NO_MDNS 55
#define MSG_PRN_MDNS_FAIL 56
/* share.c: the files that say what is shared */
#define MSG_SHR_WRITE_BESIDE 57
#define MSG_SHR_WRITE 58
#define MSG_SHR_REPLACE 59
#define MSG_SHR_EPERM 60
#define MSG_SHR_NOT_FOLDER 61
/* users.c: the accounts */
#define MSG_USR_BAD_NAME 62
#define MSG_USR_EXISTS 63
#define MSG_USR_COLON 64
#define MSG_USR_ADD_EPERM 65
#define MSG_USR_NOT_FOUND 66
#define MSG_USR_DEL_EPERM 67
/* events.c and mount.c: the kernel's event source and the mount table */
#define MSG_EVT_SOCKET_OPEN 68
#define MSG_EVT_SOCKET_BIND 69
#define MSG_EVT_DRVCTL 70
#define MSG_EVT_NO_SOURCE 71
#define MSG_EVT_NO_ROOM 72
#define MSG_MNT_NO_ROOM 73
/* common.c, the rest: host name, time zone, the processes and the clock */
#define MSG_EXEC_FAIL 74
#define MSG_NO_HOSTNAME 75
#define MSG_NO_ZONELIST 76
#define MSG_BAD_ZONE 77
#define MSG_ZONE_NOT_FOUND 78
#define MSG_ZONE_EPERM 79
#define MSG_CANNOT_LINK 80
/* 81 was "Cannot replace %s: %s.", which is MSG_SHR_REPLACE (59) */
#define MSG_NO_CMDLINE 82
#define MSG_NO_CPUTIMES 83
#define MSG_NO_MEMSIZE 84
#define MSG_NO_NETCOUNTERS 85
#define MSG_NO_DISKCOUNTERS 86
#define MSG_BAD_PROCESS 87
#define MSG_PROCESS_EPERM 88
#define MSG_PROCESS_GONE 89
#define MSG_SIGNAL_FAIL 90
#define MSG_NO_PROCLIST 91
#define MSG_NO_COMMENT_ROOM 92
#define MSG_NO_COMMENT_FILE 93
#define MSG_NO_LOCK_FILE 94
#define MSG_BAD_HOSTNAME 95
#define MSG_NO_TIMESTATE 96
#define MSG_SETCLOCK_FAIL 97
/* linux.c: NetworkManager, the Wi-Fi join and the cards */
#define MSG_LX_NM_MISSING 98
#define MSG_LX_WIFI_EPERM 99
#define MSG_LX_WIFI_BAD_SSID 100
#define MSG_LX_NM_NO_SETTINGS 101
#define MSG_LX_NM_NO_CONN 102
#define MSG_LX_NM_NO_DETAIL 103
#define MSG_LX_NM_SET_FAIL 104
#define MSG_LX_NO_CARD 105
#define MSG_LX_NM_UP_FAIL 106
/* linux.c, the rest: power, mixer, bluetooth, touchpad, files, host name,
* services, avahi, the NetBSD-only features and /proc */
#define MSG_LX_POWER_ACTION 107
#define MSG_LX_NO_SOUND 108
#define MSG_LX_MIXER_NO_VOLUME 109
#define MSG_LX_NO_MIXER 110
#define MSG_LX_NO_BLUETOOTHCTL 111
#define MSG_LX_TOUCHPAD_ENOTSUP 112
#define MSG_LX_PW_EPERM 113
#define MSG_LX_PW_BAD 114
#define MSG_LX_CHANGE_EPERM 115
#define MSG_LX_APT_UNKNOWN 116
#define MSG_LX_UPDATE_EPERM 117
#define MSG_LX_PROC_READ 118
#define MSG_LX_NO_COMMENTS 119
#define MSG_LX_COMMENT_READ 120
#define MSG_LX_COMMENT_REMOVE 121
#define MSG_LX_COMMENT_WRITE 122
#define MSG_LX_OPEN_FAIL 123
#define MSG_LX_NO_LOCK 124
#define MSG_LX_LOCK_SET 125
#define MSG_LX_LOCK_CLEAR 126
#define MSG_LX_HOSTNAME_WRITE 127
#define MSG_LX_NO_HOSTNAME_TOOL 128
#define MSG_LX_NO_TIMEDATECTL 129
#define MSG_LX_NO_SERVICE 130
#define MSG_LX_SERVICE_EPERM 131
#define MSG_LX_SERVER_MISSING 132
#define MSG_LX_NO_AVAHI 133
#define MSG_LX_SWAP_ENCRYPT 134
#define MSG_LX_CGD 135
#define MSG_LX_NPF 136
#define MSG_LX_STAT_READ 137
#define MSG_LX_STAT_EMPTY 138
#define MSG_LX_MEMINFO_READ 139
#define MSG_LX_MEMINFO_EMPTY 140
#define MSG_LX_NETDEV_READ 141
#define MSG_LX_DISKSTATS_READ 142
#define MSG_LX_EVENT_READ 143
/* netbsd.c: the NetBSD backend's sentences */
#define MSG_NB_DID_NOT_START 144
#define MSG_NB_PROC_COUNT 145
#define MSG_NB_PROC_LIST 146
#define MSG_NB_NTP_TMP 147
#define MSG_NB_READ 148
#define MSG_NB_READ2 149
#define MSG_NB_NTP_REPLACE 150
#define MSG_NB_MYNAME 151
#define MSG_NB_WRITE_BESIDE 152
#define MSG_NB_NTP_WRITE 153
#define MSG_NB_TOUCHPAD_EPERM 154
#define MSG_NB_DRVGETEVENT 155
#define MSG_NB_NO_PKGPATH 156
#define MSG_NB_NO_SALT 157
#define MSG_NB_NO_SOURCE 158
#define MSG_NB_WIFI_SCAN_EPERM 159
#define MSG_NB_RENEW_EPERM 160
#define MSG_NB_SWAP_EPERM 161
#define MSG_NB_NO_MDNSD 162
#define MSG_NB_PROC_FAST 163
#define MSG_NB_MIXER_NO_MASTER 164
#define MSG_NB_WIFI_BAD 165
#define MSG_NB_HASH_FAIL 166
#define MSG_NB_SERVER_MISSING 167
#define MSG_NB_SWAP_UNKNOWN 168
#define MSG_NB_NO_CPUTIMES 169
#define MSG_NB_NO_DISKCOUNTERS 170
#define MSG_NB_NO_IFACES 171
#define MSG_NB_NO_MEMORY 172
#define MSG_NB_NO_NCPU 173
#define MSG_NB_TOUCHPAD_FAIL 174
#define MSG_NB_SOURCE_NO_ANSWER 175
#define MSG_NB_SOURCE_BAD 176
#define MSG_NB_NO_BLUETOOTH 177
#define MSG_NB_NO_STATE_ROOM 178
#define MSG_NB_NO_VALUE_ROOM 179
#define MSG_NB_NO_CGD 180
#define MSG_NB_NO_NPF 181
#define MSG_NB_NO_TOUCHPAD 182
#define MSG_NB_TOO_MANY 183
#define MSG_NB_DHCP_RENEW 184
#define MSG_NB_DHCP_START 185
#define MSG_NB_SWAP_SYSCTL 186
/* net.c: the interfaces and the addresses */
#define MSG_NETIF_NONE 187
#define MSG_NETIF_EPERM 188
#define MSG_NETIF_BAD_V4 189
#define MSG_NETIF_BAD_MASK 190
#define MSG_NETIF_BAD_ROUTER 191
#define MSG_NETIF_BAD_V6 192
#define MSG_NETIF_BAD_DNS 193
#define MSG_NETIF_BAD_DOMAIN 194
#define MSG_NETIF_BAD_CLIENTID 195
/* logs.c: watching and reading a log */
#define MSG_LOG_NO_ROOM 196
#define MSG_LOG_NO_NAME 197
#define MSG_LOG_NO_INOTIFY 198
#define MSG_LOG_WATCH_FAIL 199
#define MSG_LOG_WATCH_ENOTSUP 200
#define MSG_LOG_NO_BUFFER 201
#define MSG_LOG_READ_FAIL 202
#define MSG_LOG_READ_FAIL2 203
/* disk_linux.c: lsblk, udisksctl and erasing a disk */
#define MSG_DISK_NO_LSBLK 204
#define MSG_DISK_NOT_FOUND 205
#define MSG_DISK_NO_UDISKS 206
#define MSG_DISK_NOT_MOUNTED 208
#define MSG_DISK_SYSTEM 209
#define MSG_DISK_CHECK_FAIL 210
#define MSG_DISK_ERASE_EPERM 211
#define MSG_DISK_BAD_NAME 212
#define MSG_DISK_NOT_DRIVE 213
#define MSG_DISK_HOLDS_SYSTEM 214
#define MSG_DISK_MOUNTED 215
#define MSG_DISK_NO_PERM_LIST 216
/* mount_linux.c */
#define MSG_MNT_NO_PROC 217
/* disk_netbsd.c: hw.disknames, disklabel, newfs and the permissions */
#define MSG_NDISK_NO_LIST 218
#define MSG_NDISK_PART_MOUNT 220
#define MSG_NDISK_PART_CHECK 223
#define MSG_NDISK_NO_DEVICE 225
#define MSG_NDISK_BAD_NAME 226
#define MSG_NDISK_PART_MISSING 230
#define MSG_NDISK_NO_MTREE 231
#define MSG_NDISK_FIX_EPERM 232
/* mount_netbsd.c */
#define MSG_NMNT_NO_TABLE 233
const char *mcde_sys_msg(int n, const char *text);
/* run ARGV (an absolute path first) and wait; MCDE_SYS_OK on exit status 0 */
int mcde_sys_run(char *const argv[]);
/* run ARGV and put what it prints (stdout, at most LEN-1 bytes) into BUF */
int mcde_sys_capture(char *const argv[], char *buf, size_t len);
/* the first of PATHS (NULL-terminated) that is an executable file, or NULL */
const char *mcde_sys_which(const char *const *paths);
/* the same, ending the child after SECONDS (tools that ask the network) */
int mcde_sys_capture_limited(char *const argv[], char *buf, size_t len,
int seconds);
/* run ARGV (with INPUT on its standard input, if not NULL) in a job that the
* caller does not wait for (common.c; McdeSys.h: mcde_sys_job_fd, _finish,
* _cancel); NULL, with mcde_sys_error(), if it cannot start */
McdeSysJob *mcde_sys_job_start(char *const argv[], const char *input);
/* run ARGV and write INPUT to its standard input (for chpasswd(8)) */
int mcde_sys_run_input(char *const argv[], const char *input);
/* the value after KEY on the first line of FILE that starts with it */
int mcde_sys_file_value(const char *file, const char *key, char *buf,
size_t len);
/* How long a question to a system tool may take when a program asks it again
* and again to show a state (the bar: volume, Bluetooth, Wi-Fi): after this
* many seconds the tool is killed and the read fails. Without it a stopped
* PulseAudio froze the bar (tasksd t0080). Not for tools that do real work
* (disks, updates): those may take minutes. */
#define MCDE_SYS_STATUS_SECONDS 2
/* the backend: the processes (mcde_sys_processes checks the arguments) */
int mcde_sys_processes_backend(McdeSysProcess **out, size_t *n);
/* mount.c: the mounts of this system, filled by the backend */
int mcde_sys_mounts_backend(McdeSysMount *m, size_t max);
/* events.c: one queued device event (1), none (0) or an error (-1) */
int mcde_sys_disk_event_read_backend(int fd, char *buf, size_t len);
/* mount.c: the device NAME is gone; unmount MOUNTPOINT the forced way (a
* lazy unmount on Linux, -f on NetBSD); the backend */
int mcde_sys_disk_force_unmount(const char *mountpoint);
/* the backends: the CPU ticks of every processor, and the memory */
int mcde_sys_cpu_times_backend(McdeSysCpu **out, size_t *n);
int mcde_sys_memory_backend(McdeSysMemory *m);
int mcde_sys_net_io_backend(McdeSysNetIo **out, size_t *n);
int mcde_sys_disk_io_backend(McdeSysDiskIo **out, size_t *n);
/* an update source the root update may use: a directory, file:/// or https://
* (not http://); 1 if so (common.c, tasksd t0078) */
int mcde_sys_update_source_ok(const char *url);
/* the backend: the fields of INFO that only the system can tell (common.c
* has filled in what POSIX gives, the backend may replace it) */
void mcde_sys_info_backend(McdeSysInfo *info);
/* the backend: Wi-Fi or not, and the network joined (net.c asks) */
McdeSysNetKind mcde_sys_if_kind(const char *name, char *ssid, size_t len);
/* net.c: an interface name that may go on a command line; the prefix
* length of a dotted netmask (-1: none) and the netmask of a prefix */
int mcde_sys_net_ifname_ok(const char *name);
/* net.c: may this network go into wpa_supplicant.conf (the checks of the
* NetBSD mcde_sys_wifi_join); 1 if so */
int mcde_sys_wifi_config_ok(const char *ifname, const char *ssid,
const char *passphrase);
/* net.c: may this network name be an argument of nmcli (Linux wifi_join) */
int mcde_sys_wifi_ssid_arg_ok(const char *ssid);
int mcde_sys_net_prefix(const char *netmask);
void mcde_sys_net_mask(int prefix, char *buf, size_t len);
/* the backend: the configured settings of IFNAME, its router, Ethernet ID
* and media into CONFIG (net.c has filled in the current addresses, the MTU
* and the DNS servers in use); and writing the configured part, checked */
int mcde_sys_net_config_backend(const char *ifname,
McdeSysNetConfig *config);
int mcde_sys_net_configure_backend(const char *ifname,
const McdeSysNetConfig *config);
/* users.c: is LOGIN a member of the administrators' group */
int mcde_sys_user_is_admin(const char *login);
/* the backend: the group whose members administer the computer */
const char *mcde_sys_admin_group(void);
/* the backend: the shell a new user gets */
const char *mcde_sys_default_shell(void);
/* the backend: the arguments of process PID, each ended by a NUL, into BUF;
* how many bytes, or -1 */
int mcde_sys_process_args(pid_t pid, char *buf, size_t len);
/* the backend: 1 when PID is stopped or a zombie, 0 when it runs, -1 when
* it cannot be asked (no such process, no permission) */
int mcde_sys_process_stopped_backend(pid_t pid);
/* the backend: a file's comment (extended attribute) and its lock (the
* immutable flag); MCDE_SYS_ENOTSUP when the file system cannot */
int mcde_sys_file_comment_get_backend(const char *path, char *buf,
size_t len);
int mcde_sys_file_comment_set_backend(const char *path, const char *text);
int mcde_sys_file_locked_get_backend(const char *path, int *locked);
int mcde_sys_file_locked_set_backend(const char *path, int locked);
/* the backend: is the system's time service on, and which server; then
* switch it on or off (needs root) */
int mcde_sys_ntp_get_backend(int *on, char *server, size_t len);
int mcde_sys_ntp_set_backend(int on, const char *server);
/* the backend: the computer's name, now and at boot (rc.conf/myname on
* NetBSD, /etc/hostname and hostnamectl on Linux) */
int mcde_sys_hostname_set_backend(const char *name);
/* the backend, for share.c: where the servers keep their configuration
* (NULL: not on this system), and how an exports(5) line reads */
const char *mcde_sys_exports_file(void);
const char *mcde_sys_smb_conf(void);
const char *mcde_sys_afp_conf(void);
void mcde_sys_export_line(const char *path, char *buf, size_t len);
/* the backend: make running servers read their configuration again */
void mcde_sys_shares_reload(void);
/* netmount.c: would URL (sftp://, nfs://, afp://) reach a command line */
int mcde_sys_net_url_ok(const char *url);
/* netmount.c: the address mount_afp is given (the password is "-"); 0 if URL is
* no address */
int mcde_sys_net_afp_address(const char *url, int has_password, char *buf,
size_t len);
/* netmount.c: a service of KIND found on HOST (NAME as it calls itself)
* into HOSTS, merged by host; the new count */
int mcde_sys_net_add(McdeSysNetHost *hosts, int n, size_t max,
const char *name, const char *host, int kind);
/* the backend: the mixer when no sound server runs (sound.c asks) */
int mcde_sys_mixer_get(int *percent, int *muted);
int mcde_sys_mixer_set(int percent);
int mcde_sys_mixer_mute(int muted);
/* the backend: the player of the system's own sound device, for a WAV file
* when no sound server runs (audioplay(1) on NetBSD), or NULL */
const char *mcde_sys_player(void);
#endif /* _McdeSys_private_h */