| 1 |
/*************************************************************************** |
/* SPDX-License-Identifier: GPL-3.0-or-later */ |
| 2 |
menu.c - description |
/* |
| 3 |
------------------- |
* menu |
| 4 |
Copyright : (C) 2004-2025 by Leaflet |
* - configurable user interactive menu feature |
| 5 |
Email : leaflet@leafok.com |
* |
| 6 |
***************************************************************************/ |
* Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com> |
| 7 |
|
*/ |
| 8 |
/*************************************************************************** |
|
| 9 |
* * |
#ifdef HAVE_CONFIG_H |
| 10 |
* This program is free software; you can redistribute it and/or modify * |
#include "config.h" |
| 11 |
* it under the terms of the GNU General Public License as published by * |
#endif |
|
* the Free Software Foundation; either version 3 of the License, or * |
|
|
* (at your option) any later version. * |
|
|
* * |
|
|
***************************************************************************/ |
|
| 12 |
|
|
| 13 |
#include "bbs.h" |
#include "bbs.h" |
| 14 |
#include "bbs_cmd.h" |
#include "bbs_cmd.h" |
| 21 |
#include "user_priv.h" |
#include "user_priv.h" |
| 22 |
#include <ctype.h> |
#include <ctype.h> |
| 23 |
#include <errno.h> |
#include <errno.h> |
| 24 |
|
#include <fcntl.h> |
| 25 |
#include <stdio.h> |
#include <stdio.h> |
| 26 |
#include <stdlib.h> |
#include <stdlib.h> |
| 27 |
#include <string.h> |
#include <string.h> |
| 28 |
#include <unistd.h> |
#include <unistd.h> |
| 29 |
#include <sys/ipc.h> |
#include <sys/mman.h> |
| 30 |
#include <sys/shm.h> |
#include <sys/stat.h> |
| 31 |
|
|
| 32 |
#define MENU_SCREEN_PATH_PREFIX "var/MENU_SCR_" |
enum _menu_constant_t |
| 33 |
#define MENU_CONF_DELIM_WITH_SPACE " ,\t\r\n" |
{ |
| 34 |
#define MENU_CONF_DELIM_WITHOUT_SPACE "\r\n" |
MENU_SET_RESERVED_LENGTH = sizeof(int16_t) * 4, |
| 35 |
|
}; |
| 36 |
|
|
| 37 |
#define MENU_SET_RESERVED_LENGTH (sizeof(int16_t) * 4) |
static const char MENU_CONF_DELIM_WITH_SPACE[] = " ,\t\r\n"; |
| 38 |
|
static const char MENU_CONF_DELIM_WITHOUT_SPACE[] = "\r\n"; |
| 39 |
|
|
| 40 |
MENU_SET bbs_menu; |
MENU_SET bbs_menu; |
| 41 |
|
MENU_SET top10_menu; |
| 42 |
|
|
| 43 |
int load_menu(MENU_SET *p_menu_set, const char *conf_file) |
int load_menu(MENU_SET *p_menu_set, const char *conf_file) |
| 44 |
{ |
{ |
| 45 |
|
char filepath[FILE_PATH_LEN]; |
| 46 |
|
int fd; |
| 47 |
|
size_t size; |
| 48 |
|
void *p_shm; |
| 49 |
FILE *fin; |
FILE *fin; |
| 50 |
int fin_line = 0; |
int fin_line = 0; |
| 51 |
char buffer[LINE_BUFFER_LEN]; |
char buffer[LINE_BUFFER_LEN]; |
| 60 |
MENU_ID menu_id; |
MENU_ID menu_id; |
| 61 |
MENU_ITEM_ID menu_item_id; |
MENU_ITEM_ID menu_item_id; |
| 62 |
MENU_SCREEN_ID screen_id; |
MENU_SCREEN_ID screen_id; |
| 63 |
int proj_id; |
|
| 64 |
key_t key; |
if (p_menu_set == NULL || conf_file == NULL) |
| 65 |
size_t size; |
{ |
| 66 |
|
log_error("NULL pointer error\n"); |
| 67 |
|
return -1; |
| 68 |
|
} |
| 69 |
|
|
| 70 |
// Initialize the data structure |
// Initialize the data structure |
| 71 |
memset(p_menu_set, 0, sizeof(*p_menu_set)); |
memset(p_menu_set, 0, sizeof(*p_menu_set)); |
| 75 |
if (p_menu_set->p_menu_name_dict == NULL) |
if (p_menu_set->p_menu_name_dict == NULL) |
| 76 |
{ |
{ |
| 77 |
log_error("trie_dict_create() error\n"); |
log_error("trie_dict_create() error\n"); |
| 78 |
return -3; |
return -1; |
| 79 |
} |
} |
| 80 |
|
|
| 81 |
// Use trie_dict to search screen_id by menu screen name |
// Use trie_dict to search screen_id by menu screen name |
| 83 |
if (p_menu_set->p_menu_screen_dict == NULL) |
if (p_menu_set->p_menu_screen_dict == NULL) |
| 84 |
{ |
{ |
| 85 |
log_error("trie_dict_create() error\n"); |
log_error("trie_dict_create() error\n"); |
| 86 |
return -3; |
return -1; |
| 87 |
} |
} |
| 88 |
|
|
| 89 |
if ((fin = fopen(conf_file, "r")) == NULL) |
if ((fin = fopen(conf_file, "r")) == NULL) |
| 93 |
} |
} |
| 94 |
|
|
| 95 |
// Allocate shared memory |
// Allocate shared memory |
|
proj_id = (int)(time(NULL) % getpid()); |
|
|
key = ftok(conf_file, proj_id); |
|
|
if (key == -1) |
|
|
{ |
|
|
log_error("ftok(%s %d) error (%d)\n", conf_file, proj_id, errno); |
|
|
return -2; |
|
|
} |
|
|
|
|
| 96 |
size = MENU_SET_RESERVED_LENGTH + |
size = MENU_SET_RESERVED_LENGTH + |
| 97 |
sizeof(MENU) * MAX_MENUS + |
sizeof(MENU) * MAX_MENUS + |
| 98 |
sizeof(MENU_ITEM) * MAX_MENUITEMS + |
sizeof(MENU_ITEM) * MAX_MENUITEMS + |
| 99 |
sizeof(MENU_SCREEN) * MAX_MENUS + |
sizeof(MENU_SCREEN) * MAX_MENUS + |
| 100 |
MAX_MENU_SCR_BUF_LENGTH * MAX_MENUS; |
MAX_MENU_SCR_BUF_LENGTH * MAX_MENUS; |
| 101 |
p_menu_set->shmid = shmget(key, size, IPC_CREAT | IPC_EXCL | 0600); |
|
| 102 |
if (p_menu_set->shmid == -1) |
strncpy(filepath, conf_file, sizeof(filepath) - 1); |
| 103 |
|
filepath[sizeof(filepath) - 1] = '\0'; |
| 104 |
|
snprintf(p_menu_set->shm_name, sizeof(p_menu_set->shm_name), "/MENU_SHM_%s", basename(filepath)); |
| 105 |
|
|
| 106 |
|
if (shm_unlink(p_menu_set->shm_name) == -1 && errno != ENOENT) |
| 107 |
|
{ |
| 108 |
|
log_error("shm_unlink(%s) error (%d)\n", p_menu_set->shm_name, errno); |
| 109 |
|
return -2; |
| 110 |
|
} |
| 111 |
|
|
| 112 |
|
if ((fd = shm_open(p_menu_set->shm_name, O_CREAT | O_EXCL | O_RDWR, 0600)) == -1) |
| 113 |
{ |
{ |
| 114 |
log_error("shmget(size = %d) error (%d)\n", size, errno); |
log_error("shm_open(%s) error (%d)\n", p_menu_set->shm_name, errno); |
| 115 |
return -3; |
return -2; |
| 116 |
|
} |
| 117 |
|
if (ftruncate(fd, (off_t)size) == -1) |
| 118 |
|
{ |
| 119 |
|
log_error("ftruncate(size=%d) error (%d)\n", size, errno); |
| 120 |
|
close(fd); |
| 121 |
|
return -2; |
| 122 |
} |
} |
| 123 |
p_menu_set->p_reserved = shmat(p_menu_set->shmid, NULL, 0); |
|
| 124 |
if (p_menu_set->p_reserved == (void *)-1) |
p_shm = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0L); |
| 125 |
|
if (p_shm == MAP_FAILED) |
| 126 |
{ |
{ |
| 127 |
log_error("shmat() error (%d)\n", errno); |
log_error("mmap() error (%d)\n", errno); |
| 128 |
return -3; |
close(fd); |
| 129 |
} |
return -2; |
| 130 |
p_menu_set->p_menu_pool = p_menu_set->p_reserved + MENU_SET_RESERVED_LENGTH; |
} |
| 131 |
p_menu_set->p_menu_item_pool = p_menu_set->p_menu_pool + sizeof(MENU) * MAX_MENUS; |
|
| 132 |
p_menu_set->p_menu_screen_pool = p_menu_set->p_menu_item_pool + sizeof(MENU_ITEM) * MAX_MENUITEMS; |
if (close(fd) < 0) |
| 133 |
p_menu_set->p_menu_screen_buf = p_menu_set->p_menu_screen_pool + sizeof(MENU_SCREEN) * MAX_MENUS; |
{ |
| 134 |
|
log_error("close(fd) error (%d)\n", errno); |
| 135 |
|
return -1; |
| 136 |
|
} |
| 137 |
|
|
| 138 |
|
p_menu_set->shm_size = size; |
| 139 |
|
p_menu_set->p_reserved = p_shm; |
| 140 |
|
|
| 141 |
|
p_menu_set->p_menu_pool = (char *)(p_menu_set->p_reserved) + MENU_SET_RESERVED_LENGTH; |
| 142 |
|
p_menu_set->p_menu_item_pool = (char *)(p_menu_set->p_menu_pool) + sizeof(MENU) * MAX_MENUS; |
| 143 |
|
p_menu_set->p_menu_screen_pool = (char *)(p_menu_set->p_menu_item_pool) + sizeof(MENU_ITEM) * MAX_MENUITEMS; |
| 144 |
|
p_menu_set->p_menu_screen_buf = (char *)(p_menu_set->p_menu_screen_pool) + sizeof(MENU_SCREEN) * MAX_MENUS; |
| 145 |
p_menu_set->p_menu_screen_buf_free = p_menu_set->p_menu_screen_buf; |
p_menu_set->p_menu_screen_buf_free = p_menu_set->p_menu_screen_buf; |
| 146 |
|
|
| 147 |
p_menu_set->menu_count = 0; |
p_menu_set->menu_count = 0; |
| 203 |
return -1; |
return -1; |
| 204 |
} |
} |
| 205 |
p = q; |
p = q; |
| 206 |
while (isalnum(*q) || *q == '_' || *q == '-') |
while (isalnum((int)*q) || *q == '_' || *q == '-') |
| 207 |
{ |
{ |
| 208 |
q++; |
q++; |
| 209 |
} |
} |
| 286 |
else |
else |
| 287 |
{ |
{ |
| 288 |
q = p; |
q = p; |
| 289 |
while (isalnum(*q) || *q == '_' || *q == '-') |
while (isalnum((int)*q) || *q == '_' || *q == '-') |
| 290 |
{ |
{ |
| 291 |
q++; |
q++; |
| 292 |
} |
} |
| 313 |
return -1; |
return -1; |
| 314 |
} |
} |
| 315 |
p = q; |
p = q; |
| 316 |
while (isdigit(*q)) |
while (isdigit((int)*q)) |
| 317 |
{ |
{ |
| 318 |
q++; |
q++; |
| 319 |
} |
} |
| 332 |
return -1; |
return -1; |
| 333 |
} |
} |
| 334 |
p = q; |
p = q; |
| 335 |
while (isdigit(*q)) |
while (isdigit((int)*q)) |
| 336 |
{ |
{ |
| 337 |
q++; |
q++; |
| 338 |
} |
} |
| 351 |
return -1; |
return -1; |
| 352 |
} |
} |
| 353 |
p = q; |
p = q; |
| 354 |
while (isdigit(*q)) |
while (isdigit((int)*q)) |
| 355 |
{ |
{ |
| 356 |
q++; |
q++; |
| 357 |
} |
} |
| 370 |
return -1; |
return -1; |
| 371 |
} |
} |
| 372 |
p = q; |
p = q; |
| 373 |
while (isdigit(*q)) |
while (isdigit((int)*q)) |
| 374 |
{ |
{ |
| 375 |
q++; |
q++; |
| 376 |
} |
} |
| 475 |
return -1; |
return -1; |
| 476 |
} |
} |
| 477 |
p = q; |
p = q; |
| 478 |
while (isdigit(*q)) |
while (isdigit((int)*q)) |
| 479 |
{ |
{ |
| 480 |
q++; |
q++; |
| 481 |
} |
} |
| 494 |
return -1; |
return -1; |
| 495 |
} |
} |
| 496 |
p = q; |
p = q; |
| 497 |
while (isdigit(*q)) |
while (isdigit((int)*q)) |
| 498 |
{ |
{ |
| 499 |
q++; |
q++; |
| 500 |
} |
} |
| 562 |
return -1; |
return -1; |
| 563 |
} |
} |
| 564 |
p = q; |
p = q; |
| 565 |
while (isdigit(*q)) |
while (isdigit((int)*q)) |
| 566 |
{ |
{ |
| 567 |
q++; |
q++; |
| 568 |
} |
} |
| 581 |
return -1; |
return -1; |
| 582 |
} |
} |
| 583 |
p = q; |
p = q; |
| 584 |
while (isdigit(*q)) |
while (isdigit((int)*q)) |
| 585 |
{ |
{ |
| 586 |
q++; |
q++; |
| 587 |
} |
} |
| 600 |
return -1; |
return -1; |
| 601 |
} |
} |
| 602 |
p = q; |
p = q; |
| 603 |
while (isalnum(*q) || *q == '_' || *q == '-') |
while (isalnum((int)*q) || *q == '_' || *q == '-') |
| 604 |
{ |
{ |
| 605 |
q++; |
q++; |
| 606 |
} |
} |
| 630 |
return -1; |
return -1; |
| 631 |
} |
} |
| 632 |
p = q; |
p = q; |
| 633 |
while (isdigit(*q)) |
while (isdigit((int)*q)) |
| 634 |
{ |
{ |
| 635 |
q++; |
q++; |
| 636 |
} |
} |
| 649 |
return -1; |
return -1; |
| 650 |
} |
} |
| 651 |
p = q; |
p = q; |
| 652 |
while (isdigit(*q)) |
while (isdigit((int)*q)) |
| 653 |
{ |
{ |
| 654 |
q++; |
q++; |
| 655 |
} |
} |
| 668 |
return -1; |
return -1; |
| 669 |
} |
} |
| 670 |
p = q; |
p = q; |
| 671 |
while (isdigit(*q)) |
while (isdigit((int)*q)) |
| 672 |
{ |
{ |
| 673 |
q++; |
q++; |
| 674 |
} |
} |
| 714 |
p_screen = get_menu_screen_by_id(p_menu_set, screen_id); |
p_screen = get_menu_screen_by_id(p_menu_set, screen_id); |
| 715 |
|
|
| 716 |
q = p; |
q = p; |
| 717 |
while (isalnum(*q) || *q == '_' || *q == '-') |
while (isalnum((int)*q) || *q == '_' || *q == '-') |
| 718 |
{ |
{ |
| 719 |
q++; |
q++; |
| 720 |
} |
} |
| 1015 |
return EXITMENU; |
return EXITMENU; |
| 1016 |
} |
} |
| 1017 |
|
|
| 1018 |
|
if (p_menu->item_count <= 0) // empty menu |
| 1019 |
|
{ |
| 1020 |
|
moveto(p_menu->screen_row, p_menu->screen_col); |
| 1021 |
|
clrtoeol(); |
| 1022 |
|
prints("没有可选项"); |
| 1023 |
|
press_any_key(); |
| 1024 |
|
return -1; |
| 1025 |
|
} |
| 1026 |
|
|
| 1027 |
menu_item_pos = p_menu_set->menu_item_pos[p_menu_set->choose_step]; |
menu_item_pos = p_menu_set->menu_item_pos[p_menu_set->choose_step]; |
| 1028 |
menu_item_id = p_menu->items[menu_item_pos]; |
menu_item_id = p_menu->items[menu_item_pos]; |
| 1029 |
p_menu_item = get_menu_item_by_id(p_menu_set, menu_item_id); |
p_menu_item = get_menu_item_by_id(p_menu_set, menu_item_id); |
| 1095 |
{ |
{ |
| 1096 |
moveto(p_menu->screen_row, p_menu->screen_col); |
moveto(p_menu->screen_row, p_menu->screen_col); |
| 1097 |
clrtoeol(); |
clrtoeol(); |
| 1098 |
prints("ûпѡ"); |
prints("没有可选项"); |
| 1099 |
press_any_key(); |
press_any_key(); |
| 1100 |
return -1; |
return -1; |
| 1101 |
} |
} |
| 1167 |
switch (key) |
switch (key) |
| 1168 |
{ |
{ |
| 1169 |
case CR: |
case CR: |
|
igetch_reset(); |
|
| 1170 |
case KEY_RIGHT: |
case KEY_RIGHT: |
| 1171 |
if (p_menu_item->submenu) |
if (p_menu_item->submenu) |
| 1172 |
{ |
{ |
| 1193 |
if (p_menu_set->choose_step > 0) |
if (p_menu_set->choose_step > 0) |
| 1194 |
{ |
{ |
| 1195 |
p_menu_set->choose_step--; |
p_menu_set->choose_step--; |
| 1196 |
if (p_menu_set->choose_step == 0) |
return REDRAW; |
|
{ |
|
|
return REDRAW; |
|
|
} |
|
|
if (display_menu(p_menu_set) != 0) |
|
|
{ |
|
|
return menu_control(p_menu_set, KEY_LEFT); |
|
|
} |
|
| 1197 |
} |
} |
| 1198 |
else |
else |
| 1199 |
{ |
{ |
| 1377 |
|
|
| 1378 |
int unload_menu(MENU_SET *p_menu_set) |
int unload_menu(MENU_SET *p_menu_set) |
| 1379 |
{ |
{ |
|
int shmid; |
|
|
|
|
| 1380 |
if (p_menu_set == NULL) |
if (p_menu_set == NULL) |
| 1381 |
{ |
{ |
| 1382 |
|
log_error("NULL pointer error\n"); |
| 1383 |
return -1; |
return -1; |
| 1384 |
} |
} |
| 1385 |
|
|
| 1395 |
p_menu_set->p_menu_screen_dict = NULL; |
p_menu_set->p_menu_screen_dict = NULL; |
| 1396 |
} |
} |
| 1397 |
|
|
|
shmid = p_menu_set->shmid; |
|
|
|
|
| 1398 |
detach_menu_shm(p_menu_set); |
detach_menu_shm(p_menu_set); |
| 1399 |
|
|
| 1400 |
if (shmctl(shmid, IPC_RMID, NULL) == -1) |
if (shm_unlink(p_menu_set->shm_name) == -1 && errno != ENOENT) |
| 1401 |
{ |
{ |
| 1402 |
log_error("shmctl(shmid=%d, IPC_RMID) error (%d)\n", shmid, errno); |
log_error("shm_unlink(%s) error (%d)\n", p_menu_set->shm_name, errno); |
| 1403 |
return -1; |
return -2; |
| 1404 |
} |
} |
| 1405 |
|
|
| 1406 |
return 0; |
return 0; |
| 1408 |
|
|
| 1409 |
int get_menu_shm_readonly(MENU_SET *p_menu_set) |
int get_menu_shm_readonly(MENU_SET *p_menu_set) |
| 1410 |
{ |
{ |
| 1411 |
|
int fd; |
| 1412 |
void *p_shm; |
void *p_shm; |
| 1413 |
|
struct stat sb; |
| 1414 |
|
size_t size; |
| 1415 |
|
|
| 1416 |
|
if (p_menu_set == NULL) |
| 1417 |
|
{ |
| 1418 |
|
log_error("NULL pointer error\n"); |
| 1419 |
|
return -1; |
| 1420 |
|
} |
| 1421 |
|
|
| 1422 |
|
if ((fd = shm_open(p_menu_set->shm_name, O_RDONLY, 0600)) == -1) |
| 1423 |
|
{ |
| 1424 |
|
log_error("shm_open(%s) error (%d)\n", p_menu_set->shm_name, errno); |
| 1425 |
|
return -2; |
| 1426 |
|
} |
| 1427 |
|
|
| 1428 |
|
if (fstat(fd, &sb) < 0) |
| 1429 |
|
{ |
| 1430 |
|
log_error("fstat(fd) error (%d)\n", errno); |
| 1431 |
|
close(fd); |
| 1432 |
|
return -2; |
| 1433 |
|
} |
| 1434 |
|
|
| 1435 |
|
size = (size_t)sb.st_size; |
| 1436 |
|
|
| 1437 |
p_shm = shmat(p_menu_set->shmid, NULL, SHM_RDONLY); |
p_shm = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0L); |
| 1438 |
if (p_shm == (void *)-1) |
if (p_shm == MAP_FAILED) |
| 1439 |
{ |
{ |
| 1440 |
log_error("shmat(menu_shm shmid = %d) error (%d)\n", p_menu_set->shmid, errno); |
log_error("mmap() error (%d)\n", errno); |
| 1441 |
|
close(fd); |
| 1442 |
|
return -2; |
| 1443 |
|
} |
| 1444 |
|
|
| 1445 |
|
if (close(fd) < 0) |
| 1446 |
|
{ |
| 1447 |
|
log_error("close(fd) error (%d)\n", errno); |
| 1448 |
return -1; |
return -1; |
| 1449 |
} |
} |
| 1450 |
|
|
| 1451 |
|
p_menu_set->shm_size = size; |
| 1452 |
p_menu_set->p_reserved = p_shm; |
p_menu_set->p_reserved = p_shm; |
| 1453 |
p_menu_set->p_menu_pool = p_menu_set->p_reserved + MENU_SET_RESERVED_LENGTH; |
|
| 1454 |
p_menu_set->p_menu_item_pool = p_menu_set->p_menu_pool + sizeof(MENU) * MAX_MENUS; |
p_menu_set->p_menu_pool = (char *)(p_menu_set->p_reserved) + MENU_SET_RESERVED_LENGTH; |
| 1455 |
p_menu_set->p_menu_screen_pool = p_menu_set->p_menu_item_pool + sizeof(MENU_ITEM) * MAX_MENUITEMS; |
p_menu_set->p_menu_item_pool = (char *)(p_menu_set->p_menu_pool) + sizeof(MENU) * MAX_MENUS; |
| 1456 |
p_menu_set->p_menu_screen_buf = p_menu_set->p_menu_screen_pool + sizeof(MENU_SCREEN) * MAX_MENUS; |
p_menu_set->p_menu_screen_pool = (char *)(p_menu_set->p_menu_item_pool) + sizeof(MENU_ITEM) * MAX_MENUITEMS; |
| 1457 |
|
p_menu_set->p_menu_screen_buf = (char *)(p_menu_set->p_menu_screen_pool) + sizeof(MENU_SCREEN) * MAX_MENUS; |
| 1458 |
p_menu_set->p_menu_screen_buf_free = p_menu_set->p_menu_screen_buf; |
p_menu_set->p_menu_screen_buf_free = p_menu_set->p_menu_screen_buf; |
| 1459 |
|
|
| 1460 |
p_menu_set->choose_step = 0; |
p_menu_set->choose_step = 0; |
| 1466 |
|
|
| 1467 |
int set_menu_shm_readonly(MENU_SET *p_menu_set) |
int set_menu_shm_readonly(MENU_SET *p_menu_set) |
| 1468 |
{ |
{ |
| 1469 |
void *p_shm; |
if (p_menu_set == NULL) |
|
|
|
|
// Remap shared memory in read-only mode |
|
|
p_shm = shmat(p_menu_set->shmid, p_menu_set->p_reserved, SHM_RDONLY | SHM_REMAP); |
|
|
if (p_shm == (void *)-1) |
|
| 1470 |
{ |
{ |
| 1471 |
log_error("shmat(menu_shm shmid = %d) error (%d)\n", p_menu_set->shmid, errno); |
log_error("NULL pointer error\n"); |
| 1472 |
return -1; |
return -1; |
| 1473 |
} |
} |
| 1474 |
|
|
| 1475 |
p_menu_set->p_reserved = p_shm; |
if (p_menu_set->p_reserved != NULL && mprotect(p_menu_set->p_reserved, p_menu_set->shm_size, PROT_READ) < 0) |
| 1476 |
|
{ |
| 1477 |
|
log_error("mprotect() error (%d)\n", errno); |
| 1478 |
|
return -2; |
| 1479 |
|
} |
| 1480 |
|
|
| 1481 |
return 0; |
return 0; |
| 1482 |
} |
} |
| 1483 |
|
|
| 1484 |
int detach_menu_shm(MENU_SET *p_menu_set) |
int detach_menu_shm(MENU_SET *p_menu_set) |
| 1485 |
{ |
{ |
| 1486 |
|
if (p_menu_set == NULL) |
| 1487 |
|
{ |
| 1488 |
|
log_error("NULL pointer error\n"); |
| 1489 |
|
return -1; |
| 1490 |
|
} |
| 1491 |
|
|
| 1492 |
p_menu_set->menu_count = 0; |
p_menu_set->menu_count = 0; |
| 1493 |
p_menu_set->menu_item_count = 0; |
p_menu_set->menu_item_count = 0; |
| 1494 |
p_menu_set->menu_screen_count = 0; |
p_menu_set->menu_screen_count = 0; |
| 1503 |
p_menu_set->p_menu_name_dict = NULL; |
p_menu_set->p_menu_name_dict = NULL; |
| 1504 |
p_menu_set->p_menu_screen_dict = NULL; |
p_menu_set->p_menu_screen_dict = NULL; |
| 1505 |
|
|
| 1506 |
if (p_menu_set->p_reserved != NULL && shmdt(p_menu_set->p_reserved) == -1) |
if (p_menu_set->p_reserved != NULL && munmap(p_menu_set->p_reserved, p_menu_set->shm_size) < 0) |
| 1507 |
{ |
{ |
| 1508 |
log_error("shmdt() error (%d)\n", errno); |
log_error("munmap() error (%d)\n", errno); |
| 1509 |
return -1; |
return -2; |
| 1510 |
} |
} |
| 1511 |
|
|
| 1512 |
p_menu_set->p_reserved = NULL; |
p_menu_set->p_reserved = NULL; |