ztmux 0.1.0

A Rust port of tmux — the full terminal multiplexer, server and client
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
// Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
//
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
// IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
// OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
use std::borrow::Cow;
use std::path::PathBuf;
use std::sync::OnceLock;


use crate::compat::getopt::{OPTARG, OPTIND, getopt};
use crate::compat::{S_ISDIR, fdforkpty::getptmfd, getprogname::getprogname};
use crate::libc::{
    CLOCK_MONOTONIC, CLOCK_REALTIME, CODESET, EEXIST, F_GETFL, F_SETFL, LC_CTYPE, LC_TIME,
    O_NONBLOCK, S_IRWXO, S_IRWXU, X_OK, access, clock_gettime, fcntl, getpwuid, getuid, lstat,
    mkdir, nl_langinfo, setlocale, stat, strchr, strcspn, strerror, strncmp, strrchr, timespec,
};
use crate::*;
use crate::options_::{options, options_create, options_default, options_set_number, options_set_string};

pub static mut GLOBAL_OPTIONS: *mut options = null_mut();
pub static mut GLOBAL_S_OPTIONS: *mut options = null_mut();
pub static mut GLOBAL_W_OPTIONS: *mut options = null_mut();
pub static mut GLOBAL_ENVIRON: *mut environ = null_mut();

pub static mut START_TIME: timeval = timeval {
    tv_sec: 0,
    tv_usec: 0,
};

pub static mut SOCKET_PATH: *const u8 = null_mut();

pub static mut PTM_FD: c_int = -1;

pub static mut SHELL_COMMAND: *mut u8 = null_mut();

/// C `vendor/tmux/tmux.c:53`: `static __dead void usage(int status)`
pub fn usage() -> ! {
    eprintln!(
        "usage: ztmux [-2CDlNuVv] [-c shell-command] [-f file] [-L socket-name]\n             [-S socket-path] [-T features] [command [flags]]\n"
    );
    std::process::exit(1)
}

/// C `vendor/tmux/tmux.c:63`: `static const char *getshell(void)`
unsafe fn getshell() -> Cow<'static, CStr> {
    unsafe {
        if let Ok(shell) = std::env::var("SHELL")
            && let shell = CString::new(shell).unwrap()
            && checkshell(Some(&shell))
        {
            return Cow::Owned(shell);
        }

        if let Some(pw) = NonNull::new(getpwuid(getuid()))
            && !(*pw.as_ptr()).pw_shell.is_null()
            && checkshell(Some(CStr::from_ptr((*pw.as_ptr()).pw_shell)))
        {
            return Cow::Owned(CString::new(cstr_to_str((*pw.as_ptr()).pw_shell.cast())).unwrap());
        }

        Cow::Borrowed(CStr::from_ptr(_PATH_BSHELL.cast()))
    }
}

/// C `vendor/tmux/tmux.c:80`: `int checkshell(const char *shell)`
pub unsafe fn checkshell(shell: Option<&CStr>) -> bool {
    unsafe {
        let Some(shell) = shell else {
            return false;
        };
        if shell.to_bytes()[0] != b'/' {
            return false;
        }
        if areshell(shell) {
            return false;
        }
        if access(shell.as_ptr().cast(), X_OK) != 0 {
            return false;
        }
    }
    true
}

pub unsafe fn checkshell_(shell: *const u8) -> bool {
    unsafe {
        if shell.is_null() {
            return false;
        }
        if *shell != b'/' {
            return false;
        }
        if areshell(CStr::from_ptr(shell.cast())) {
            return false;
        }
        if access(shell.cast(), X_OK) != 0 {
            return false;
        }
    }
    true
}

/// C `vendor/tmux/tmux.c:92`: `static int areshell(const char *shell)`
unsafe fn areshell(shell: &CStr) -> bool {
    unsafe {
        let ptr = strrchr(shell.as_ptr().cast(), b'/' as c_int);
        let ptr = if !ptr.is_null() {
            ptr.wrapping_add(1)
        } else {
            shell.as_ptr().cast()
        };
        let mut progname = getprogname();
        if *progname == b'-' {
            progname = progname.wrapping_add(1);
        }
        libc::strcmp(ptr, progname) == 0
    }
}

/// C `vendor/tmux/tmux.c:109`: `static char *expand_path(const char *path, const char *home)`
unsafe fn expand_path(path: *const u8, home: Option<&CStr>) -> Option<CString> {
    unsafe {
        if strncmp(path, c!("~/"), 2) == 0 {
            return Some(
                CString::new(format!("{}{}", home?.to_str().unwrap(), _s(path.add(1)))).unwrap(),
            );
        }

        if *path == b'$' {
            let mut end: *const u8 = strchr(path, b'/' as i32).cast();
            let name = if end.is_null() {
                xstrdup(path.add(1)).cast().as_ptr()
            } else {
                xstrndup(path.add(1), end.addr() - path.addr() - 1)
                    .cast()
                    .as_ptr()
            };
            let value = environ_find(GLOBAL_ENVIRON, name);
            free_(name);
            if value.is_null() {
                return None;
            }
            if end.is_null() {
                end = c!("");
            }
            return Some(
                CString::new(format!("{}{}", _s(transmute_ptr((*value).value)), _s(end))).unwrap(),
            );
        }

        Some(CString::new(cstr_to_str(path)).unwrap())
    }
}

/// C `vendor/tmux/tmux.c:142`: `static void expand_paths(const char *s, char ***paths, u_int *n, int no_realpath)`
unsafe fn expand_paths(s: &str, paths: &mut Vec<CString>, ignore_errors: i32) {
    unsafe {
        let home = find_home();
        let mut path: CString;

        let func = "expand_paths";

        paths.clear();

        let mut next: *const u8;
        let mut tmp: *mut u8 = xstrdup__(s);
        let copy = tmp;
        while {
            next = strsep(&raw mut tmp as _, c!(":").cast());
            !next.is_null()
        } {
            let Some(expanded) = expand_path(next, home) else {
                log_debug!("{func}: invalid path: {}", _s(next));
                continue;
            };

            match PathBuf::from(expanded.to_str().unwrap()).canonicalize() {
                Ok(resolved) => {
                    path = CString::new(resolved.into_os_string().into_string().unwrap()).unwrap();
                    // free_(expanded);
                }
                Err(_) => {
                    log_debug!(
                        "{func}: realpath(\"{}\") failed: {}",
                        expanded.to_string_lossy(),
                        strerror(errno!()),
                    );
                    if ignore_errors != 0 {
                        // free_(expanded);
                        continue;
                    }
                    path = expanded;
                }
            }

            if paths.contains(&path) {
                log_debug!("{func}: duplicate path: {}", path.to_string_lossy());
                // free_(path);
                continue;
            }

            paths.push(path);
        }
        free_(copy);
    }
}

/// C `vendor/tmux/tmux.c:187`: `static char *make_label(const char *label, char **cause)`
unsafe fn make_label(mut label: *const u8, cause: *mut *mut u8) -> *const u8 {
    let mut paths: Vec<CString> = Vec::new();
    let base: *mut u8;
    let mut sb: stat = unsafe { zeroed() }; // TODO use uninit

    unsafe {
        'fail: {
            *cause = null_mut();
            if label.is_null() {
                label = c!("default");
            }
            let uid = getuid();

            expand_paths(TMUX_SOCK, &mut paths, 1);
            if paths.is_empty() {
                *cause = format_nul!("no suitable socket path");
                return null_mut();
            }

            paths.truncate(1);
            let mut path = paths.pop().unwrap(); /* can only have one socket! */

            base = format_nul!("{}/ztmux-{}", path.to_string_lossy(), uid);
            if mkdir(base.cast(), S_IRWXU) != 0 && errno!() != EEXIST {
                *cause = format_nul!(
                    "couldn't create directory {} ({})",
                    _s(base),
                    strerror(errno!())
                );
                break 'fail;
            }
            if lstat(base.cast(), &raw mut sb) != 0 {
                *cause = format_nul!(
                    "couldn't read directory {} ({})",
                    _s(base),
                    strerror(errno!()),
                );
                break 'fail;
            }
            if !S_ISDIR(sb.st_mode) {
                *cause = format_nul!("{} is not a directory", _s(base));
                break 'fail;
            }
            if sb.st_uid != uid || (sb.st_mode & S_IRWXO) != 0 {
                *cause = format_nul!("directory {} has unsafe permissions", _s(base));
                break 'fail;
            }
            path = CString::new(format!("{}/{}", _s(base), _s(label))).unwrap();
            free_(base);
            return path.into_raw().cast();
        }

        // fail:
        free_(base);
        null_mut()
    }
}

/// C `vendor/tmux/tmux.c:239`: `char *shell_argv0(const char *shell, int is_login)`
pub unsafe fn shell_argv0(shell: *const u8, is_login: c_int) -> *mut u8 {
    unsafe {
        let slash = strrchr(shell, b'/' as _);
        let name = if !slash.is_null() && *slash.add(1) != b'\0' {
            slash.add(1)
        } else {
            shell
        };

        if is_login != 0 {
            format_nul!("-{}", _s(name))
        } else {
            format_nul!("{}", _s(name))
        }
    }
}

/// C `vendor/tmux/tmux.c:257`: `void setblocking(int fd, int state)`
pub unsafe fn setblocking(fd: c_int, state: c_int) {
    unsafe {
        let mut mode = fcntl(fd, F_GETFL);

        if mode != -1 {
            if state == 0 {
                mode |= O_NONBLOCK;
            } else {
                mode &= !O_NONBLOCK;
            }
            fcntl(fd, F_SETFL, mode);
        }
    }
}

/// C `vendor/tmux/tmux.c:285`: `char *clean_name(const char *name, int untrusted)`
pub unsafe fn clean_name(name: *const u8, untrusted: c_int) -> *mut u8 {
    unsafe {
        if !utf8_isvalid(name) {
            return null_mut();
        }
        let copy = xstrdup(name).as_ptr();
        let mut cp = copy;
        while *cp != b'\0' {
            if untrusted != 0 && *cp == b'#' && *cp.add(1) == b'(' {
                *cp = b'_';
            }
            cp = cp.add(1);
        }
        let mut new_name: *mut u8 = null_mut();
        utf8_stravis(
            &raw mut new_name,
            copy,
            vis_flags::VIS_OCTAL | vis_flags::VIS_CSTYLE | vis_flags::VIS_TAB | vis_flags::VIS_NL,
        );
        free_(copy);
        new_name
    }
}

/// C `vendor/tmux/tmux.c:271`: `uint64_t get_timer(void)`
pub unsafe fn get_timer() -> u64 {
    unsafe {
        let mut ts: timespec = zeroed();
        // We want a timestamp in milliseconds suitable for time measurement,
        // so prefer the monotonic clock.
        if clock_gettime(CLOCK_MONOTONIC, &raw mut ts) != 0 {
            clock_gettime(CLOCK_REALTIME, &raw mut ts);
        }
        (ts.tv_sec as u64 * 1000) + (ts.tv_nsec as u64 / 1000000)
    }
}

/// C `vendor/tmux/tmux.c:323`: `const char *find_cwd(void)`
pub fn find_cwd() -> Option<PathBuf> {
    let cwd = std::env::current_dir().ok()?;

    let pwd = match std::env::var("PWD") {
        Ok(val) if !val.is_empty() => PathBuf::from(val),
        _ => return Some(cwd),
    };

    // We want to use PWD so that symbolic links are maintained,
    // but only if it matches the actual working directory.

    let Ok(resolved1) = pwd.canonicalize() else {
        return Some(cwd);
    };

    let Ok(resolved2) = cwd.canonicalize() else {
        return Some(cwd);
    };

    if resolved1 == resolved2 {
        return Some(cwd);
    }

    Some(pwd)
}

/// C `vendor/tmux/tmux.c:348`: `const char *find_home(void)`
pub fn find_home() -> Option<&'static CStr> {
    unsafe {
        static HOME: OnceLock<Option<CString>> = OnceLock::new();
        HOME.get_or_init(|| match std::env::var("HOME") {
            Ok(home) if !home.is_empty() => Some(CString::new(home).unwrap()),
            _ => NonNull::new(getpwuid(getuid()))
                .map(|pw| CString::new(cstr_to_str((*pw.as_ptr()).pw_dir.cast())).unwrap()),
        })
        .as_deref()
    }
}

/// C `vendor/tmux/tmux.c:369`: `const char *getversion(void)`
pub fn getversion() -> &'static str {
    crate::TMUX_VERSION
}

/// Entrypoint for tmux binary
///
/// # Safety
///
/// This code is work in progress. There is no guarantee that the code is safe.
/// This function should only be called by the tmux binary crate to start tmux.
pub unsafe fn tmux_main(mut argc: i32, mut argv: *mut *mut u8, _env: *mut *mut u8) {
    std::panic::set_hook(Box::new(|_panic_info| {
        let backtrace = std::backtrace::Backtrace::capture();
        let err_str = format!("{backtrace:#?}");
        _ = std::fs::write("client-panic.txt", err_str);
    }));

    unsafe {
        // setproctitle_init(argc, argv.cast(), env.cast());
        let mut cause: *mut u8 = null_mut();
        let mut path: *const u8 = null_mut();
        let mut label: *mut u8 = null_mut();
        let mut feat: i32 = 0;
        let mut fflag: i32 = 0;
        let mut flags: client_flag = client_flag::empty();

        if setlocale(LC_CTYPE, c!("en_US.UTF-8")).is_null()
            && setlocale(LC_CTYPE, c!("C.UTF-8")).is_null()
        {
            if setlocale(LC_CTYPE, c!("")).is_null() {
                eprintln!("invalid LC_ALL, LC_CTYPE or LANG");
                std::process::exit(1);
            }
            let s: *mut u8 = nl_langinfo(CODESET).cast();
            if !strcaseeq_(s, "UTF-8") && !strcaseeq_(s, "UTF8") {
                eprintln!("need UTF-8 locale (LC_CTYPE) but have {}", _s(s));
                std::process::exit(1);
            }
        }

        setlocale(LC_TIME, c!(""));
        tzset();

        if **argv == b'-' {
            flags = client_flag::LOGIN;
        }

        GLOBAL_ENVIRON = environ_create().as_ptr();

        let mut var = environ;
        while !(*var).is_null() {
            environ_put(GLOBAL_ENVIRON, *var, environ_flags::empty());
            var = var.add(1);
        }

        if let Some(cwd) = find_cwd() {
            environ_set!(
                GLOBAL_ENVIRON,
                c!("PWD"),
                environ_flags::empty(),
                "{}",
                cwd.to_str().unwrap()
            );
        }
        expand_paths(TMUX_CONF, &mut CFG_FILES.lock().unwrap(), 1);

        while let Some(opt) = getopt(argc, argv.cast(), c!("2c:CDdf:lL:NqS:T:uUvV")) {
            match opt {
                b'2' => tty_add_features(&raw mut feat, "256", c!(":,")),
                b'c' => SHELL_COMMAND = OPTARG.cast(),
                b'D' => flags |= client_flag::NOFORK,
                b'C' => {
                    if flags.intersects(client_flag::CONTROL) {
                        flags |= client_flag::CONTROLCONTROL;
                    } else {
                        flags |= client_flag::CONTROL;
                    }
                }
                b'f' => {
                    if fflag == 0 {
                        fflag = 1;
                        CFG_FILES.lock().unwrap().clear();
                    }
                    CFG_FILES
                        .lock()
                        .unwrap()
                        .push(CString::new(cstr_to_str(OPTARG)).unwrap());
                    CFG_QUIET.store(false, atomic::Ordering::Relaxed);
                }
                b'V' => {
                    println!("ztmux {}", getversion());
                    std::process::exit(0);
                }
                b'l' => flags |= client_flag::LOGIN,
                b'L' => {
                    free(label as _);
                    label = xstrdup(OPTARG.cast()).cast().as_ptr();
                }
                b'N' => flags |= client_flag::NOSTARTSERVER,
                b'q' => (),
                b'S' => {
                    free(path as _);
                    path = xstrdup(OPTARG.cast()).cast().as_ptr();
                }
                b'T' => tty_add_features(&raw mut feat, cstr_to_str(OPTARG.cast()), c!(":,")),
                b'u' => flags |= client_flag::UTF8,
                b'v' => log_add_level(),
                _ => usage(),
            }
        }
        argc -= OPTIND;
        argv = argv.add(OPTIND as usize);

        if !SHELL_COMMAND.is_null() && argc != 0 {
            usage();
        }
        if flags.intersects(client_flag::NOFORK) && argc != 0 {
            usage();
        }

        PTM_FD = getptmfd();
        if PTM_FD == -1 {
            eprintln!("getptmfd failed!");
            std::process::exit(1);
        }

        /*
        // TODO no pledge on linux
            if pledge("stdio rpath wpath cpath flock fattr unix getpw sendfd recvfd proc exec tty ps", null_mut()) != 0 {
                err(1, "pledge");
        }
        */

        // tmux is a UTF-8 terminal, so if TMUX is set, assume UTF-8.
        // Otherwise, if the user has set LC_ALL, LC_CTYPE or LANG to contain
        // UTF-8, it is a safe assumption that either they are using a UTF-8
        // terminal, or if not they know that output from UTF-8-capable
        // programs may be wrong.
        if std::env::var("TMUX").is_ok() {
            flags |= client_flag::UTF8;
        } else {
            let s = std::env::var("LC_ALL")
                .or_else(|_| std::env::var("LC_CTYPE"))
                .or_else(|_| std::env::var("LANG"))
                .unwrap_or_default()
                .to_ascii_lowercase();

            if s.contains("utf-8") || s.contains("utf8") {
                flags |= client_flag::UTF8;
            }
        }

        GLOBAL_OPTIONS = options_create(null_mut());
        GLOBAL_S_OPTIONS = options_create(null_mut());
        GLOBAL_W_OPTIONS = options_create(null_mut());

        for oe in &OPTIONS_TABLE {
            if oe.scope & OPTIONS_TABLE_SERVER != 0 {
                options_default(GLOBAL_OPTIONS, oe);
            }
            if oe.scope & OPTIONS_TABLE_SESSION != 0 {
                options_default(GLOBAL_S_OPTIONS, oe);
            }
            if oe.scope & OPTIONS_TABLE_WINDOW != 0 {
                options_default(GLOBAL_W_OPTIONS, oe);
            }
        }

        // The default shell comes from SHELL or from the user's passwd entry if available.
        options_set_string!(
            GLOBAL_S_OPTIONS,
            "default-shell",
            false,
            "{}",
            getshell().to_string_lossy(),
        );

        // Override keys to vi if VISUAL or EDITOR are set.
        if let Ok(s) = std::env::var("VISUAL").or_else(|_| std::env::var("EDITOR")) {
            options_set_string!(GLOBAL_OPTIONS, "editor", false, "{s}");

            let s = if let Some(slash_end) = s.rfind('/') {
                &s[slash_end + 1..]
            } else {
                &s
            };

            let keys = if s.contains("vi") {
                modekey::MODEKEY_VI
            } else {
                modekey::MODEKEY_EMACS
            };
            options_set_number(GLOBAL_S_OPTIONS, "status-keys", keys as _);
            options_set_number(GLOBAL_W_OPTIONS, "mode-keys", keys as _);
        }

        // If socket is specified on the command-line with -S or -L, it is
        // used. Otherwise, $TMUX is checked and if that fails "default" is
        // used.
        if path.is_null()
            && label.is_null()
            && let Ok(s) = std::env::var("TMUX")
            && !s.is_empty()
            && s.as_bytes()[0] != b','
        {
            let tmp: *mut u8 = xstrdup__(&s);
            *tmp.add(strcspn(tmp, c!(","))) = b'\0';
            path = tmp;
        }
        if path.is_null() {
            path = make_label(label.cast(), &raw mut cause);
            if path.is_null() {
                if !cause.is_null() {
                    eprintln!("{}", _s(cause));
                    free(cause as _);
                }
                std::process::exit(1);
            }
            flags |= client_flag::DEFAULTSOCKET;
        }
        SOCKET_PATH = path;
        free_(label);

        // ztmux extension: `ztmux dashboard` launches the live ratatui dashboard
        // (src/extensions) as a client subcommand instead of a server command,
        // targeting the socket resolved above.
        if argc >= 1 && !(*argv).is_null() {
            let cmd = CStr::from_ptr((*argv).cast()).to_bytes();
            if cmd == b"dashboard" || cmd == b"switch" || cmd == b"tree" {
                let sock = if SOCKET_PATH.is_null() {
                    String::new()
                } else {
                    CStr::from_ptr(SOCKET_PATH.cast()).to_string_lossy().into_owned()
                };
                let code = match cmd {
                    b"switch" => crate::extensions::switch::run(&sock),
                    b"tree" => crate::extensions::tree::run(&sock),
                    _ => crate::extensions::dashboard::run(&sock),
                };
                std::process::exit(code);
            }
        }

        // Pass control to the client.
        std::process::exit(client_main(osdep_event_init(), argc, argv, flags, feat))
    }
}