1
/* -*- mode: c; coding: utf-8; after-save-hook: (lambda () (let* ((find-build-directory (lambda (try-directory &optional base-directory) (let ((base-directory (or base-directory try-directory))) (cond ((equal try-directory "/") base-directory) ((file-readable-p (concat (file-name-as-directory try-directory) "Makefile")) try-directory) ((funcall find-build-directory (directory-file-name (file-name-directory try-directory)) base-directory)))))) (build-directory (funcall find-build-directory (buffer-file-name))) (local-build-directory (if (fboundp 'file-local-name) (file-local-name build-directory) (or (file-remote-p build-directory 'localname) build-directory))) (command (file-relative-name (file-name-sans-extension (buffer-file-name)) build-directory))) (pcase (progn (if (get-buffer "*Test*") (kill-buffer "*Test*")) (process-file-shell-command (let ((qbdir (shell-quote-argument local-build-directory)) (qcmd (shell-quote-argument command))) (format "cd %s && CFLAGS=-Werror make --silent %s && %s --test --verbose" qbdir qcmd qcmd)) nil "*Test*")) (0 (let ((w (get-buffer-window "*Test*"))) (if w (delete-window w)))) (_ (with-current-buffer "*Test*" (compilation-mode) (cd-absolute build-directory)) (display-buffer "*Test*" '(display-buffer-in-side-window)))))); -*- */
1
/* -*- coding: utf-8; lexical-binding: t -*- */
3
3
* Mandos password agent - Simple password agent to run Mandos client
5
* Copyright © 2019-2020 Teddy Hogeborn
6
* Copyright © 2019-2020 Björn Påhlsson
5
* Copyright © 2019-2022 Teddy Hogeborn
6
* Copyright © 2019-2022 Björn Påhlsson
8
8
* This file is part of Mandos.
1098
1098
} ievent_buffer;
1099
1099
struct inotify_event *const ievent = &ievent_buffer.event;
1101
#if defined(__GNUC__) and __GNUC__ >= 7
1102
#pragma GCC diagnostic push
1103
/* ievent is pointing into a struct which is of sufficient size */
1104
#pragma GCC diagnostic ignored "-Wstringop-overflow"
1101
1106
const ssize_t read_length = read(fd, ievent, ievent_size);
1107
#if defined(__GNUC__) and __GNUC__ >= 7
1108
#pragma GCC diagnostic pop
1102
1110
if(read_length == 0){ /* EOF */
1103
1111
error(0, 0, "Got EOF from inotify fd for directory %s", filename);
1104
1112
*quit_now = true;
1480
1488
if(send_buffer == NULL){
1481
1489
error(0, errno, "Failed to allocate send_buffer");
1491
#if defined(__GNUC__) and __GNUC__ >= 5
1492
#pragma GCC diagnostic push
1493
/* mlock() does not access the memory */
1494
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
1483
1496
if(mlock(send_buffer, send_buffer_length) != 0){
1497
#if defined(__GNUC__) and __GNUC__ >= 5
1498
#pragma GCC diagnostic pop
1484
1500
/* Warn but do not treat as fatal error */
1485
1501
if(errno != EPERM and errno != ENOMEM){
1486
1502
error(0, errno, "Failed to lock memory for password"
2653
2669
bool password_is_read = false;
2654
2670
const char helper_directory[] = "/nonexistent";
2655
2671
const char *const argv[] = { "/bin/sh", "-c",
2656
"echo -n ${MANDOSPLUGINHELPERDIR}", NULL };
2672
"printf %s \"${MANDOSPLUGINHELPERDIR}\"", NULL };
2658
2674
const bool success = start_mandos_client(queue, epoll_fd,
2659
2675
&mandos_client_exited,
4182
4198
memcpy(ievent->name, dummy_file_name, sizeof(dummy_file_name));
4183
4199
const size_t ievent_size = (sizeof(struct inotify_event)
4184
4200
+ sizeof(dummy_file_name));
4201
#if defined(__GNUC__) and __GNUC__ >= 11
4202
#pragma GCC diagnostic push
4203
/* ievent is pointing into a struct which is of sufficient size */
4204
#pragma GCC diagnostic ignored "-Wstringop-overread"
4185
4206
g_assert_cmpint(write(pipefds[1], (char *)ievent, ievent_size),
4186
4207
==, ievent_size);
4208
#if defined(__GNUC__) and __GNUC__ >= 11
4209
#pragma GCC diagnostic pop
4187
4211
g_assert_cmpint(close(pipefds[1]), ==, 0);
4189
4213
bool quit_now = false;
4277
4301
memcpy(ievent->name, dummy_file_name, sizeof(dummy_file_name));
4278
4302
const size_t ievent_size = (sizeof(struct inotify_event)
4279
4303
+ sizeof(dummy_file_name));
4304
#if defined(__GNUC__) and __GNUC__ >= 11
4305
#pragma GCC diagnostic push
4306
/* ievent is pointing into a struct which is of sufficient size */
4307
#pragma GCC diagnostic ignored "-Wstringop-overread"
4280
4309
g_assert_cmpint(write(pipefds[1], (char *)ievent, ievent_size),
4281
4310
==, ievent_size);
4311
#if defined(__GNUC__) and __GNUC__ >= 11
4312
#pragma GCC diagnostic pop
4282
4314
g_assert_cmpint(close(pipefds[1]), ==, 0);
4284
4316
bool quit_now = false;
4374
4406
memcpy(ievent->name, dummy_file_name, sizeof(dummy_file_name));
4375
4407
const size_t ievent_size = (sizeof(struct inotify_event)
4376
4408
+ sizeof(dummy_file_name));
4409
#if defined(__GNUC__) and __GNUC__ >= 11
4410
#pragma GCC diagnostic push
4411
/* ievent is pointing into a struct which is of sufficient size */
4412
#pragma GCC diagnostic ignored "-Wstringop-overread"
4377
4414
g_assert_cmpint(write(pipefds[1], (char *)ievent, ievent_size),
4378
4415
==, ievent_size);
4416
#if defined(__GNUC__) and __GNUC__ >= 11
4417
#pragma GCC diagnostic pop
4379
4419
g_assert_cmpint(close(pipefds[1]), ==, 0);
4381
4421
bool quit_now = false;
4459
4499
memcpy(ievent->name, dummy_file_name, sizeof(dummy_file_name));
4460
4500
const size_t ievent_size = (sizeof(struct inotify_event)
4461
4501
+ sizeof(dummy_file_name));
4502
#if defined(__GNUC__) and __GNUC__ >= 11
4503
#pragma GCC diagnostic push
4504
/* ievent is pointing into a struct which is of sufficient size */
4505
#pragma GCC diagnostic ignored "-Wstringop-overread"
4462
4507
g_assert_cmpint(write(pipefds[1], (char *)ievent, ievent_size),
4463
4508
==, ievent_size);
4509
#if defined(__GNUC__) and __GNUC__ >= 11
4510
#pragma GCC diagnostic pop
4464
4512
g_assert_cmpint(close(pipefds[1]), ==, 0);
4466
4514
bool quit_now = false;
4543
4591
memcpy(ievent->name, dummy_file_name, sizeof(dummy_file_name));
4544
4592
const size_t ievent_size = (sizeof(struct inotify_event)
4545
4593
+ sizeof(dummy_file_name));
4594
#if defined(__GNUC__) and __GNUC__ >= 11
4595
#pragma GCC diagnostic push
4596
/* ievent is pointing into a struct which is of sufficient size */
4597
#pragma GCC diagnostic ignored "-Wstringop-overread"
4546
4599
g_assert_cmpint(write(pipefds[1], (char *)ievent, ievent_size),
4547
4600
==, ievent_size);
4601
#if defined(__GNUC__) and __GNUC__ >= 11
4602
#pragma GCC diagnostic pop
4548
4604
g_assert_cmpint(close(pipefds[1]), ==, 0);
4550
4606
bool quit_now = false;
4619
4675
memcpy(ievent->name, dummy_file_name, sizeof(dummy_file_name));
4620
4676
const size_t ievent_size = (sizeof(struct inotify_event)
4621
4677
+ sizeof(dummy_file_name));
4678
#if defined(__GNUC__) and __GNUC__ >= 11
4679
#pragma GCC diagnostic push
4680
/* ievent is pointing into a struct which is of sufficient size */
4681
#pragma GCC diagnostic ignored "-Wstringop-overread"
4622
4683
g_assert_cmpint(write(pipefds[1], (char *)ievent, ievent_size),
4623
4684
==, ievent_size);
4685
#if defined(__GNUC__) and __GNUC__ >= 11
4686
#pragma GCC diagnostic pop
4624
4688
g_assert_cmpint(close(pipefds[1]), ==, 0);
4626
4690
bool quit_now = false;
4698
4762
memcpy(ievent->name, dummy_file_name, sizeof(dummy_file_name));
4699
4763
const size_t ievent_size = (sizeof(struct inotify_event)
4700
4764
+ sizeof(dummy_file_name));
4765
#if defined(__GNUC__) and __GNUC__ >= 11
4766
#pragma GCC diagnostic push
4767
/* ievent is pointing into a struct which is of sufficient size */
4768
#pragma GCC diagnostic ignored "-Wstringop-overread"
4701
4770
g_assert_cmpint(write(pipefds[1], (char *)ievent, ievent_size),
4702
4771
==, ievent_size);
4772
#if defined(__GNUC__) and __GNUC__ >= 11
4773
#pragma GCC diagnostic pop
4703
4775
g_assert_cmpint(close(pipefds[1]), ==, 0);
4705
4777
bool quit_now = false;
4783
4855
memcpy(ievent->name, dummy_file_name, sizeof(dummy_file_name));
4784
4856
const size_t ievent_size = (sizeof(struct inotify_event)
4785
4857
+ sizeof(dummy_file_name));
4858
#if defined(__GNUC__) and __GNUC__ >= 11
4859
#pragma GCC diagnostic push
4860
/* ievent is pointing into a struct which is of sufficient size */
4861
#pragma GCC diagnostic ignored "-Wstringop-overread"
4786
4863
g_assert_cmpint(write(pipefds[1], (char *)ievent, ievent_size),
4787
4864
==, ievent_size);
4865
#if defined(__GNUC__) and __GNUC__ >= 11
4866
#pragma GCC diagnostic pop
4788
4868
g_assert_cmpint(close(pipefds[1]), ==, 0);
4790
4870
bool quit_now = false;
8193
8275
g_option_context_free(context);
8194
8276
return should_run_tests != FALSE;
8283
(if (not (funcall run-tests-in-test-buffer default-directory))
8284
(funcall show-test-buffer-in-test-window)
8285
(funcall remove-test-window)))
8286
run-tests-in-test-buffer:
8288
(with-current-buffer (get-buffer-create "*Test*")
8289
(setq buffer-read-only nil
8290
default-directory dir)
8293
(let ((process-result
8294
(let ((inhibit-read-only t))
8295
(process-file-shell-command
8296
(funcall get-command-line) nil "*Test*"))))
8297
(and (numberp process-result)
8298
(= process-result 0))))
8303
(funcall find-build-directory (buffer-file-name)))
8304
(local-build-directory
8305
(if (fboundp 'file-local-name)
8306
(file-local-name build-directory)
8307
(or (file-remote-p build-directory 'localname)
8310
(file-relative-name (file-name-sans-extension
8311
(buffer-file-name)) build-directory))
8312
(qbdir (shell-quote-argument local-build-directory))
8313
(qcmd (shell-quote-argument command)))
8314
(format (concat "cd %s && CFLAGS=-Werror make --silent %s"
8315
" && %s --test --verbose") qbdir qcmd qcmd)))
8316
find-build-directory:
8317
(lambda (try-directory &optional base-directory)
8318
(let ((base-directory (or base-directory try-directory)))
8319
(cond ((equal try-directory "/") base-directory)
8321
(concat (file-name-as-directory try-directory)
8322
"Makefile")) try-directory)
8323
((funcall find-build-directory
8324
(directory-file-name (file-name-directory
8327
show-test-buffer-in-test-window:
8329
(when (not (get-buffer-window-list "*Test*"))
8330
(setq next-error-last-buffer (get-buffer "*Test*"))
8331
(let* ((side (if (>= (window-width) 146) 'right 'bottom))
8332
(display-buffer-overriding-action
8333
`((display-buffer-in-side-window) (side . ,side)
8334
(window-height . fit-window-to-buffer)
8335
(window-width . fit-window-to-buffer))))
8336
(display-buffer "*Test*"))))
8339
(let ((test-window (get-buffer-window "*Test*")))
8340
(if test-window (delete-window test-window))))
8341
eval: (add-hook 'after-save-hook run-tests 90 t)