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 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525
use std::os::raw::{c_char, c_int, c_uint, c_void}; /// Do not edit the rootfs to change the hostname /// /// --- /// **version:** 1.0.0 pub const LXC_CLONE_KEEPNAME: u32 = 1 << 0; /// Do not change the MAC address on network interfaces /// /// --- /// **version:** 1.0.0 pub const LXC_CLONE_KEEPMACADDR: u32 = 1 << 1; /// Snapshot the original filesystem(s) /// /// --- /// **version:** 1.0.0 pub const LXC_CLONE_SNAPSHOT: u32 = 1 << 2; /// Use the same bdev type /// /// --- /// **version:** 1.0.0 pub const LXC_CLONE_KEEPBDEVTYPE: u32 = 1 << 3; /// Snapshot only if bdev supports it, else copy /// /// --- /// **version:** 1.0.0 pub const LXC_CLONE_MAYBE_SNAPSHOT: u32 = 1 << 4; /// Number of `LXC_CLONE_*` flags /// /// --- /// **version:** 1.0.0 pub const LXC_CLONE_MAXFLAGS: u32 = 1 << 5; /// Redirect `stdin` to `/dev/zero` and `stdout` and `stderr` to `/dev/null` /// /// --- /// **version:** 1.0.0 pub const LXC_CREATE_QUIET: u32 = 1 << 0; /// Number of `LXC_CREATE*` flags /// /// --- /// **version:** 1.0.0 pub const LXC_CREATE_MAXFLAGS: u32 = 1 << 1; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct bdev_specs { _unused: [u8; 0], } #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct lxc_lock { _unused: [u8; 0], } /// An LXC container. /// /// --- /// **version:** 1.0.0 #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct lxc_container { /// Name of container. name: *mut c_char, /// Full path to configuration file configfile: *mut c_char, /// File to store pid. pidfile: *mut c_char, /// Container semaphore lock. slock: *mut lxc_lock, /// Container private lock. privlock: *mut lxc_lock, /// Number of references to this container. /// /// --- /// **note:** protected by privlock. numthreads: c_int, /// Container configuration. lxc_conf: *mut c_void, /// Human-readable string representing last error /// /// --- /// **version:** 1.0.0 pub error_string: *mut c_char, /// Last error number /// /// --- /// **version:** 1.0.0 pub error_num: c_int, /// Whether container wishes to be daemonized /// /// --- /// **version:** 1.0.0 pub daemonize: bool, /// Full path to configuration file /// /// --- /// **version:** 1.0.0 pub config_path: *mut c_char, /// Determine if `/var/lib/lxc/$name/config` exists. /// /// --- /// **Parameters** /// /// **c** Container. /// /// --- /// **Returns** /// /// `true` if container is defined, else `false`. /// /// --- /// **version:** 1.0.0 pub is_defined: unsafe extern "C" fn(c: *mut lxc_container) -> bool, /// Determine state of container. /// /// --- /// **Parameters** /// /// **c** Container. /// /// --- /// **Returns** /// /// Static upper-case string representing state of container. /// /// --- /// **note:** Returned string must not be freed. /// /// --- /// **version:** 1.0.0 pub state: unsafe extern "C" fn(c: *mut lxc_container) -> *const c_char, /// Determine if container is running. /// /// --- /// **Parameters** /// /// **c** Container. /// /// --- /// **Returns** /// /// `true` on success, else `false`. /// /// --- /// **version:** 1.0.0 pub is_running: unsafe extern "C" fn(c: *mut lxc_container) -> bool, /// Freeze running container. /// /// --- /// **Parameters** /// /// **c** Container. /// --- /// **Returns** /// /// `true` on success, else `false`. /// /// --- /// **version:** 1.0.0 pub freeze: unsafe extern "C" fn(c: *mut lxc_container) -> bool, /// Thaw a frozen container. /// /// --- /// **Parameters** /// /// **c** Container. /// /// --- /// **Returns** /// /// `true` on success, else `false`. /// /// --- /// **version:** 1.0.0 pub unfeeze: unsafe extern "C" fn(c: *mut lxc_container) -> bool, /// Determine process ID of the containers init process. /// /// --- /// **Parameters** /// /// **c** Container. /// /// --- /// **Returns** /// /// pid of init process as seen from outside the container. /// /// --- /// **version:** 1.0.0 pub init_pid: unsafe extern "C" fn(c: *mut lxc_container) -> c_uint, /// Load the specified configuration for the container. /// /// --- /// **Parameters** /// /// **c** Container. /// /// **alt_file** Full path to alternate configuration file, or /// `NULL` to use the default configuration file. /// /// --- /// **Returns** /// /// `true` on success, else `false`. /// /// --- /// **version:** 1.0.0 pub load_config: unsafe extern "C" fn( c: *mut lxc_container, alt_file: *const c_char, ) -> bool, /// Start the container. /// /// --- /// **Parameters** /// /// **c** Container. /// /// **useinit** Use lxcinit rather than `/sbin/init`. /// /// **argv** Array of arguments to pass to init. /// /// --- /// **Returns** /// /// `true` on success, else `false`. /// /// --- /// **version:** 1.0.0 pub start: unsafe extern "C" fn( c: *mut lxc_container, useinit: c_int, argv: *const *mut c_char, ), /// Start the container (list variant). /// /// --- /// **Parameters** /// /// **c** Container. /// /// **useinit** Use lxcinit rather than `/sbin/init`. /// /// **...** Command-line to pass to init (must end in `NULL`). /// /// --- /// **Returns** /// /// `true` on success, else `false`. /// /// --- /// **note:** Identical to [start](#structfield.start) except that that the /// init arguments are specified via a list rather than an array of /// pointers. /// /// --- /// **version:** 1.0.0 pub start1: unsafe extern "C" fn( c: *mut lxc_container, useinit: c_int, ... ) -> bool, /// Stop the container. /// /// --- /// **Parameters** /// /// **c** Container. /// /// --- /// **Returns** /// /// `true` on success, else `false`. /// /// --- /// **version:** 1.0.0 pub stop: unsafe extern "C" fn(c: *mut lxc_container) -> bool, /// Determine if the container wants to run disconnected /// from the terminal. /// /// --- /// **Parameters** /// /// **c** Container. /// /// **state** Value for the daemonize bit (0 or 1). /// /// --- /// **Returns** /// /// `true` if container wants to be daemonised, else `false`. /// /// --- /// **version:** 1.0.0 pub want_daemonize: unsafe extern "C" fn(c: *mut lxc_container, state: bool) -> bool, /// Determine whether container wishes all file descriptors /// to be closed on startup. /// /// --- /// **Parameters** /// /// **c** Container. /// /// **state** Value for the close_all_fds bit (0 or 1). /// /// --- /// **Returns** /// /// `true` if container wants all file descriptors closed, /// else `false`. /// /// --- /// **version:** 1.0.0 pub want_close_all_fds: unsafe extern "C" fn(c: *mut lxc_container, state: bool) -> bool, /// Return current config file name. /// /// --- /// **Parameters** /// /// **c** Container. /// /// --- /// **Returns** /// /// config file name, or `NULL` on error. /// /// --- /// **note:** The result is allocated, so the caller must free the result. /// /// --- /// **version:** 1.0.0 pub config_file_name: unsafe extern "C" fn(c: *mut lxc_container) -> *mut c_char, /// Wait for container to reach a particular state. /// /// --- /// **Parameters** /// /// **c** Container. /// /// **state** State to wait for. /// /// **timeout** Timeout in seconds. /// /// --- /// **Returns** /// /// `true` if state reached within `timeout,` else `false`. /// /// --- /// **note:** A `timeout` of `-1` means wait forever. A `timeout` /// of `0` means do not wait. /// /// --- /// **version:** 1.0.0 pub wait: unsafe extern "C" fn( c: *mut lxc_container, state: *const c_char, timeout: c_int, ) -> bool, /// Set a key/value configuration option. /// /// --- /// **Parameters** /// /// **c** Container. /// /// **key** Name of option to set. /// /// **value** Value of `name` to set. /// /// --- /// **Returns** /// /// `true` on success, else `false`. /// /// --- /// **version:** 1.0.0 pub set_config_item: unsafe extern "C" fn( c: *mut lxc_container, key: *const c_char, value: *const c_char, ) -> bool, /// Delete the container. /// /// --- /// **Parameters** /// /// **c** Container. /// /// --- /// **Returns** /// /// `true` on success, else `false`. /// /// --- /// **note:** Container must be stopped and have no dependent snapshots. /// /// --- /// **version:** 1.0.0 pub destroy: unsafe extern "C" fn(c: *mut lxc_container) -> bool, /// Save configuaration to a file. /// /// --- /// **Parameters** /// /// **c** Container. /// /// **alt_file** Full path to file to save configuration in. /// /// --- /// **Returns** /// /// `true` on success, else `false`. /// /// --- /// **version:** 1.0.0 pub save_config: unsafe extern "C" fn( c: *mut lxc_container, alt_file: *const c_char, ) -> bool, /// Create a container. /// /// --- /// **Parameters** /// /// **c** Container (with lxcpath, name and a starting configuration set). /// /// **t** Template to execute to instantiate the root filesystem and adjust /// the configuration. /// /// **bdevtype** Backing store type to use (if `NULL,` `dir` will be used). /// /// **specs** Additional parameters for the backing store (for example LVM /// volume group to use). /// /// **flags** `LXC_CREATE_*` options (currently only /// [LXC_CREATE_QUIET](constant.LXC_CREATE_QUIET.html) is supported). /// /// **argv** Arguments to pass to the template, terminated by `NULL` /// (if no arguments are required, just pass `NULL)`. /// /// --- /// **Returns** /// /// `true` on success, else `false`. /// /// --- /// **version:** 1.0.0 pub create: unsafe extern "C" fn( c: *mut lxc_container, t: *const c_char, bdevtype: *const c_char, specs: *mut bdev_specs, flags: c_int, argv: *const *mut c_char, ) -> bool, /// Create a container (list variant). /// /// --- /// **Parameters** /// /// **c** Container (with lxcpath, name and a starting configuration set). /// /// **t** Template to execute to instantiate the root filesystem and adjust /// the configuration. /// /// **bdevtype** Backing store type to use (if `NULL,` `dir` will be used). /// /// **specs** Additional parameters for the backing store (for example LVM /// volume group to use). /// /// **flags** `LXC_CREATE_*` options (currently only /// [LXC_CREATE_QUIET](constant.LXC_CREATE_QUIET.html) is supported). /// /// **...** Command-line to pass to init (must end in `NULL)`. /// /// --- /// **Returns** /// /// `true` on success, else `false`. /// /// --- /// **note:** Identical to [create](#structfield.create) except that the /// template arguments are specified as a list rather than an array of /// pointers. /// /// --- /// **version:** 1.0.0 pub createl: unsafe extern "C" fn( c: *mut lxc_container, t: *const c_char, bdevtype: *const c_char, specs: *mut bdev_specs, flags: c_int, ... ) -> bool, /// Rename a container /// /// --- /// **Parameters** /// /// **c** Container. /// /// **newname** New name to be used for the container. /// /// --- /// **Returns** /// /// `true` on success, else `false`. /// /// --- /// **version:** 1.0.0 pub rename: unsafe extern "C" fn( c: *mut lxc_container, newname: *const c_char, ) -> bool, /// Request the container reboot by sending it `SIGINT`. /// /// --- /// **Parameters** /// /// **c** Container. /// /// --- /// **Returns** /// `true` if reboot request successful, else `false`. /// /// --- /// **version:** 1.0.0 pub reboot: unsafe extern "C" fn(c: *mut lxc_container) -> bool, /// Request the container shutdown by sending it `SIGPWR`. /// /// --- /// **Parameters** /// /// **c** Container. /// /// **timeout** Seconds to wait before returning false. (-1 to wait forever, /// 0 to avoid waiting). /// /// --- /// **Returns** /// /// `true` if the container was shutdown successfully, else `false`. /// /// --- /// **version:** 1.0.0 pub shutdown: unsafe extern "C" fn(c: *mut lxc_container, timeout: c_int) -> bool, /// Completely clear the containers in-memory configuration. /// /// --- /// **Parameters** /// /// **c** Container. /// /// --- /// **version:** 1.0.0 pub clear_config: unsafe extern "C" fn(c: *mut lxc_container) -> c_void, /// Clear a configuration item. /// /// --- /// **Parameters** /// /// **c** Container. /// /// **key** Name of option to clear. /// /// --- /// **Returns** /// /// `true` on success, else `false`. /// /// --- /// **note:** Analog of [set_config_item](#structfield.set_config_item). /// /// --- /// **version:** 1.0.0 pub clear_config_item: unsafe extern "C" fn(c: *mut lxc_container, key: *const c_char) -> bool, /// Retrieve the value of a config item. /// /// --- /// **Parameters** /// /// **c** Container. /// /// **key** Name of option to get. /// /// **retv** *out* Caller-allocated buffer to write value of `key` into (or /// `NULL` to determine length of value). /// /// **inlen** Length of `retv` (may be zero). /// /// --- /// **Returns** /// /// Length of config items value, or < 0 on error. /// /// --- /// **note:** The caller can (and should) determine how large a buffer to /// allocate for `retv` by initially passing its value as `NULL` and /// considering the return value. This function can then be called again /// passing a newly-allocated suitably-sized buffer. /// /// **note:** If `retv` is NULL, `inlen` is ignored. /// /// **note:** If `inlen` is smaller than required, the value written to /// `retv` will be truncated. /// /// --- /// **version:** 1.0.0 pub get_config_item: unsafe extern "C" fn( c: *mut lxc_container, key: *const c_char, retv: *mut c_char, inlen: c_int, ) -> c_int, /// Retrieve the value of a config item from running container. /// /// --- /// **Parameters** /// /// **c** Container. /// /// **key** Name of option to get. /// /// --- /// **Returns** /// /// the item or NULL on error. /// /// --- /// **note:** Returned string must be freed by the caller. /// /// --- /// **version:** 1.0.0 pub get_running_config_item: unsafe extern "C" fn( c: *mut lxc_container, key: *const c_char, ) -> *mut c_char, /// Retrieve a list of config item keys given a key prefix /// /// --- /// **Parameters** /// /// **c** Container. /// /// **key** Name of option to get. /// /// **retv** *out* Caller-allocated buffer to write list of keys to (or /// `NULL` to determine overall length of keys list). /// /// **inlen** Length of `retv` (may be zero). /// /// --- /// **Returns** /// /// Length of keys list, or < 0 on error. /// /// --- /// **note:** The list values written to `retv` are separated by a newline /// character ('\\n'). /// /// **note:** The caller can (and should) determine how large a buffer to /// allocate for `retv` by initially passing its value as `NULL` and /// considering the return value. This function can then be called again /// passing a newly-allocated suitably-sized buffer. /// /// **note:** If `retv` is NULL, `inlen` is ignored. /// /// **note:** If `inlen` is smaller than required, the value written to /// `retv` will be truncated. /// /// --- /// **version:** 1.0.0 pub get_keys: unsafe extern "C" fn( c: *mut lxc_container, key: *const c_char, retv: *mut c_char, inlen: c_int, ) -> c_int, /// Obtain a list of network interfaces. /// /// --- /// **Parameters** /// /// **c** Container. /// /// --- /// **Returns** /// /// Newly-allocated array of network interfaces, or `NULL` on error. /// /// --- /// **note:** The returned array is allocated, so the caller must free it. /// /// **note:** The returned array is terminated with a `NULL` entry. /// /// --- /// **version:** 1.0.0 pub get_interfaces: unsafe extern "C" fn(c: *mut lxc_container) -> *mut *mut c_char, /// Determine the list of container IP addresses. /// /// --- /// **Parameters** /// /// **c** Container. /// /// **interface** Network interface name to consider. /// /// **family** Network family (for example "inet", "inet6"). /// /// **scope** IPv6 scope id (ignored if `family` is not "inet6"). /// /// --- /// **Returns** /// /// Newly-allocated array of network interfaces, or `NULL` on error. /// /// --- /// **note:** The returned array is allocated, so the caller must free it. /// /// **note:** The returned array is terminated with a `NULL` entry. /// /// --- /// **version:** 1.0.0 pub get_ips: unsafe extern "C" fn( c: *mut lxc_container, interface: *const c_char, family: *const c_char, scope: c_int, ) -> *mut *mut c_char, /// Retrieve the specified cgroup subsystem value for the container. /// /// --- /// **Parameters** /// /// **c** Container. /// /// **subsys** cgroup subsystem to retrieve. /// /// **retv** *out* Caller-allocated buffer to write value of `subsys` into /// (or `NULL` to determine length of value). /// /// **inlen** length of `retv` (may be zero). /// /// --- /// **Returns** /// /// Length of `subsys` value, or < 0 on error. /// /// --- /// **note:** If `retv` is `NULL,` `inlen` is ignored. /// /// **note:** If `inlen` is smaller than required, the value written to /// `retv` will be truncated. /// /// --- /// **version:** 1.0.0 pub get_cgroup_item: unsafe extern "C" fn( c: *mut lxc_container, subsys: *const c_char, retv: *mut c_char, inlen: c_int, ) -> c_int, /// Set the specified cgroup subsystem value for the container. /// /// --- /// **Parameters** /// /// **c** Container. /// /// **subsys** cgroup subsystem to consider. /// /// **value** Value to set for `subsys`. /// /// --- /// **Returns** /// /// `true` on success, else `false`. /// /// --- /// **version:** 1.0.0 pub set_cgroup_item: unsafe extern "C" fn( c: *mut lxc_container, subsys: *const c_char, value: *const c_char, ) -> bool, /// Determine full path to the containers configuration file. /// Each container can have a custom configuration path. However /// by default it will be set to either the `LXCPATH` configure /// variable, or the lxcpath value in the `LXC_GLOBAL_CONF` configuration /// file (i.e. `/etc/lxc/lxc`.conf). /// The value for a specific container can be changed using /// [set_config_path](#structfield.set_config_path). There is no other way /// to specify this in general at the moment. /// /// --- /// **Parameters** /// /// **c** Container. /// /// --- /// **Returns** /// /// Static string representing full path to configuration file. /// /// --- /// **note:** Returned string must not be freed. /// /// --- /// **version:** 1.0.0 pub get_config_path: unsafe extern "C" fn(c: *mut lxc_container) -> *const c_char, /// Set the full path to the containers configuration file. /// /// --- /// **Parameters** /// /// **c** Container. /// /// **path** Full path to configuration file. /// /// --- /// **Returns** /// /// `true` on success, else `false`. /// /// --- /// **version:** 1.0.0 pub set_config_path: unsafe extern "C" fn( c: *mut lxc_container, path: *const c_char, ) -> bool, /// Copy a stopped container. /// /// --- /// **Parameters** /// /// **c** Original container. /// /// **newname** New name for the container. If `NULL,` the same name is /// used and a new lxcpath MUST be specified. /// /// **lxcpath** lxcpath in which to create the new container. If `NULL,` /// the original container's lxcpath will be used. /// /// **flags** Additional `LXC_CLONE*` flags to change the cloning behaviour: /// - [LXC_CLONE_KEEPNAME](constant.LXC_CLONE_KEEPNAME.html) /// - [LXC_CLONE_KEEPMACADDR](constant.LXC_CLONE_KEEPMACADDR.html) /// - [LXC_CLONE_SNAPSHOT](constant.LXC_CLONE_SNAPSHOT.html) /// /// **bdevtype** Optionally force the cloned bdevtype to a specified plugin. /// By default the original is used (subject to snapshot requirements). /// /// **bdevdata** Information about how to create the new storage (i.e. /// fstype and fsdata). /// /// **newsize** In case of a block device backing store, an optional size. /// If `0,` the original backing store's size will be used if possible. Note /// this only applies to the rootfs. For any other filesystems, the original /// size will be duplicated. /// /// **hookargs** Additional arguments to pass to the clone hook script. /// /// --- /// **Returns** /// /// Newly-allocated copy of container `c,` or `NULL` on error. /// /// --- /// **note:** If devtype was not specified, and `flags` contains /// [LXC_CLONE_SNAPSHOT](constant.LXC_CLONE_SNAPSHOT.html) then use the /// native `bdevtype` if possible, else use an overlayfs. /// /// --- /// **version:** 1.0.0 pub clone: unsafe extern "C" fn( c: *mut lxc_container, newname: *const c_char, lxcpath: *const c_char, flags: c_int, bdevtype: *const c_char, bdevdata: *const c_char, newsize: u64, hookargs: *mut *mut c_char, ) -> *mut lxc_container, /// Allocate a console tty for the container. /// /// --- /// **Parameters** /// /// **c** Container. /// /// **ttynum** *in,out* Terminal number to attempt to allocate, or `-1` to /// allocate the first available tty. /// /// **masterfd** *out* File descriptor refering to the master side of the /// pty. /// /// --- /// **Returns** /// /// tty file descriptor number on success, or `-1` on failure. /// /// --- /// **note:** On successful return, `ttynum` will contain the tty number /// that was allocated. /// /// **note:** The returned file descriptor is used to keep the tty /// allocated. The caller should call close(2) on the returned file /// descriptor when no longer required so that it may be allocated /// by another caller. /// /// --- /// **version:** 1.0.0 pub console_getfd: unsafe extern "C" fn( c: *mut lxc_container, ttynum: *mut c_int, masterfd: *mut c_int, ) -> c_int, /// Allocate and run a console tty. /// /// --- /// **Parameters** /// /// **c** Container. /// /// **ttynum** Terminal number to attempt to allocate, `-1` to /// allocate the first available tty or `0` to allocate the /// console. /// /// **stdinfd** File descriptor to read input from. /// /// **stdoutfd** File descriptor to write output to. /// /// **stderrfd** File descriptor to write error output to. /// /// **escape** The escape character (1 == 'a', 2 == 'b', ...). /// /// --- /// **Returns** /// /// `0` on success, `-1` on failure. /// /// --- /// **note:** This function will not return until the console has been /// exited by the user. /// /// --- /// **version:** 1.0.0 pub console: unsafe extern "C" fn( c: *mut lxc_container, ttynum: c_int, stdinfd: c_int, stdoutfd: c_int, stderrfd: c_int, escape: c_int, ) -> c_int, /// Create a sub-process attached to a container and run a function inside /// it. /// /// --- /// **Parameters** /// /// **c** Container. /// /// **exec_function** Function to run. /// /// **exec_payload** Data to pass to `exec_function`. /// /// **options** See /// [lxc_attach_options_t](struct.lxc_attach_options_t.html). /// /// **attached_process** *out* Process ID of process running inside /// container `c` that is running `exec_function`. /// /// --- /// **Returns** /// /// `0` on success, `-1` on error. /// /// --- /// **version:** 1.0.0 pub attach: unsafe extern "C" fn( c: *mut lxc_container, exec_function: crate::attach_options::lxc_attach_exec_t, exec_payload: *mut c_void, options: crate::attach_options::lxc_attach_options_t, attached_process: c_uint, ) -> c_int, /// Run a program inside a container and wait for it to exit. /// /// --- /// **Parameters** /// /// **c** Container. /// /// **options** See /// [lxc_attach_options_t](struct.lxc_attach_options_t.html). /// /// **program** Full path inside container of program to run. /// /// **argv** Array of arguments to pass to `program`. /// /// --- /// **Returns** /// /// `waitpid(2)` status of exited process that ran `program,` or `-1` on /// error. /// /// --- /// **version:** 1.0.0 pub attach_run_wait: unsafe extern "C" fn( c: *mut lxc_container, options: crate::attach_options::lxc_attach_options_t, program: *const c_char, argv: *const *const c_char, ) -> c_int, /// Run a program inside a container and wait for it to exit (list variant). /// /// --- /// **Parameters** /// /// **c** Container. /// /// **options** See /// [lxc_attach_options_t](struct.lxc_attach_options_t.html). /// /// **program** Full path inside container of program to run. /// /// **...** Command-line to pass to `program` (must end in `NULL)`. /// /// --- /// **Returns** /// /// `waitpid(2)` status of exited process that ran `program,` or `-1` on /// error. /// /// --- /// **version:** 1.0.0 pub attach_run_wait1: unsafe extern "C" fn( c: *mut lxc_container, options: crate::attach_options::lxc_attach_options_t, program: *const c_char, ... ) -> c_int, /// Create a container snapshot. /// /// Assuming default paths, snapshots will be created as /// `/var/lib/lxc/<c>/snaps/snap<n>` where `<c>` represents the container /// name and `<n>` represents the zero-based snapshot number. /// /// --- /// **Parameters** /// /// **c** Container. /// /// **commentfile** Full path to file containing a description of the /// snapshot. /// /// --- /// **Returns** /// /// -1 on error, or zero-based snapshot number. /// /// --- /// **note:** `commentfile` may be `NULL` but this is discouraged. /// /// --- /// **version:** 1.0.0 pub snapshot: unsafe extern "C" fn( c: *mut lxc_container, commentfile: *const c_char, ) -> c_int, /// Obtain a list of container snapshots. /// /// --- /// **Parameters** /// /// **c** Container. /// /// **snapshots** Dynamically-allocated Array of lxc_snapshot's. /// /// --- /// **Returns** /// /// Number of snapshots. /// /// --- /// **note:** The array returned in `snapshots` is allocated, so the caller /// must free it. /// /// **note:** To free an individual snapshot as returned in \p /// snapshots, call the snapshots `free` function (see /// `src/tests/snapshot.c` for an example). /// /// --- /// **version:** 1.0.0 pub snapshot_list: unsafe extern "C" fn( c: *mut lxc_container, snapshots: *mut *mut lxc_snapshot, ) -> c_int, /// Create a new container based on a snapshot. /// /// The restored container will be a copy (not snapshot) of the snapshot, /// and restored in the lxcpath of the original container. /// /// --- /// **Parameters** /// /// **c** Container. /// /// **snapname** Name of snapshot. /// /// **newname** Name to be used for the restored snapshot. /// /// --- /// **Returns** /// /// `true` on success, else `false`. /// /// --- /// **warning:** If `newname` is the same as the current container /// name, the container will be destroyed. However, this will /// fail if the snapshot is overlay-based, since the snapshots /// will pin the original container. /// /// **note:** As an example, if the container exists as `/var/lib/lxc/c1,` /// snapname might be `'snap0'` (representing `/var/lib/lxcsnaps/c1/snap0)`. /// If `newname` is `c2,` then `snap0` will be copied to `/var/lib/lxc/c2`. /// /// --- /// **version:** 1.0.0 pub snapshot_restore: unsafe extern "C" fn( c: *mut lxc_container, snapname: *const c_char, newname: *const c_char, ) -> bool, /// Destroy the specified snapshot. /// /// --- /// **Parameters** /// /// **c** Container. /// /// **snapname** Name of snapshot. /// /// --- /// **Returns** /// /// `true` on success, else `false`. /// /// --- /// **version:** 1.0.0 pub snapshot_destroy: unsafe extern "C" fn( c: *mut lxc_container, snapname: *const c_char, ) -> bool, /// Determine if the caller may control the container. /// /// --- /// **Parameters** /// /// **c** Container. /// /// --- /// **Returns** /// /// `false` if there is a control socket for the container monitor and the /// caller may not access it, otherwise returns `true`. /// /// --- /// **version:** 1.0.0 pub may_control: unsafe extern "C" fn(c: *mut lxc_container) -> bool, /// Add specified device to the container. /// /// --- /// **Parameters** /// /// **c** Container. /// /// **src_path** Full path of the device. /// /// **dest_path** Alternate path in the container (or `NULL` to use /// `src_path)`. /// /// --- /// **Returns** /// `true` on success, else `false`. /// /// --- /// **version:** 1.0.0 pub add_device_node: unsafe extern "C" fn( c: *mut lxc_container, src_path: *const c_char, dest_path: *const c_char, ) -> bool, /// Remove specified device from the container. /// /// --- /// **Parameters** /// /// **c** Container. /// /// **src_path** Full path of the device. /// /// **dest_path** Alternate path in the container (or `NULL` to use /// `src_path)`. /// /// --- /// **Returns** /// `true` on success, else `false`. /// /// --- /// **version:** 1.0.0 pub remove_device_node: unsafe extern "C" fn( c: *mut lxc_container, src_path: *const c_char, dest_path: *const c_char, ) -> bool, } /// An LXC container snapshot. /// /// --- /// **version:** 1.0.0 #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct lxc_snapshot { /// Name of snapshot /// /// --- /// **version:** 1.0.0 pub name: *mut c_char, /// Full path to snapshots comment file (may be `NULL)` /// /// --- /// **version:** 1.0.0 pub comment_pathname: *mut c_char, /// Time snapshot was created /// /// --- /// **version:** 1.0.0 pub timestamp: *mut c_char, /// Full path to LXCPATH for snapshot /// /// --- /// **version:** 1.0.0 pub lxcpath: *mut c_char, /// De-allocate the snapshot. /// /// --- /// **Parameters** /// /// **s** Snapshot. /// /// --- /// **version:** 1.0.0 pub free: unsafe extern "C" fn(s: *mut lxc_snapshot) -> c_void, } extern "C" { /// Create a new container. /// /// --- /// **Parameters** /// /// **name** Name to use for container. /// /// **configpath** Full path to configuration file to use. /// /// --- /// **Returns** /// /// Newly-allocated container, or `NULL` on error. /// /// --- /// **version:** 1.0.0 pub fn lxc_container_new( name: *const c_char, configpath: *const c_char, ) -> *mut lxc_container; /// Add a reference to the specified container. /// /// --- /// **Parameters** /// /// **c** Container. /// /// --- /// **Returns** /// /// `true` on success, `false` on error. /// /// --- /// **version:** 1.0.0 pub fn lxc_container_get(lxc_container: *mut lxc_container) -> c_int; /// Drop a reference to the specified container. /// /// --- /// **Parameters** /// /// **c** Container. /// /// --- /// **Returns** /// /// `0` on success, `1` if reference was successfully dropped and container /// has been freed, and `-1` on error. /// /// --- /// **warning:** If `1` is returned, `c` is no longer valid. /// /// --- /// **version:** 1.0.0 pub fn lxc_container_put(lxc_container: *mut lxc_container) -> c_int; /// Obtain a list of all container states. /// /// --- /// **Parameters** /// /// **states** *out* states Caller-allocated array to hold all states /// (may be `NULL)`. /// /// --- /// **Returns** /// /// Number of container states. /// /// --- /// **note:** Passing `NULL` for `states` allows the caller to first /// calculate how many states there are before calling the function again, /// the second time providing a suitably-sized array to store the static /// string pointers in. /// /// **note:** The `states` array should be freed by the caller, but not the /// strings the elements point to. /// /// --- /// **version:** 1.0.0 pub fn lxc_get_wait_states(states: *mut *const c_char) -> c_int; /// Get the value for a global config key /// /// --- /// **Parameters** /// /// **key** The name of the config key /// /// --- /// **Returns** /// /// String representing the current value for the key. /// /// --- /// **version:** 1.0.0 pub fn lxc_get_global_config_item(key: *const c_char) -> *const c_char; /// Determine version of LXC. /// /// --- /// **Returns** /// /// Static string representing version of LXC in use. /// /// --- /// **note:** Returned string must not be freed. /// /// --- /// **version:** 1.0.0 pub fn lxc_get_version() -> *const c_char; /// Get a list of defined containers in a lxcpath. /// /// --- /// **Parameters** /// /// **lxcpath** lxcpath under which to look. /// /// **names** If not `NULL,` then a list of container names will be returned /// here. /// /// **cret** If not `NULL,` then a list of lxc_containers will be returned /// here. /// /// --- /// **Returns** /// /// Number of containers found, or `-1` on error. /// /// --- /// **note:** Values returned in `cret` are sorted by container name. /// /// --- /// **version:** 1.0.0 pub fn list_defined_containers( lxcpath: *const c_char, names: *mut *mut *mut c_char, cret: *mut *mut *mut lxc_container, ) -> *const c_int; /// Get a list of active containers for a given lxcpath. /// /// --- /// **Parameters** /// /// **lxcpath** Full `LXCPATH` path to consider. /// /// **names** *out* Dynamically-allocated array of container names. /// /// **cret** *out* Dynamically-allocated list of containers. /// /// --- /// **Returns** /// Number of containers found, or -1 on error. /// /// --- /// **note:** Some of the containers may not be "defined". /// /// **note:** Values returned in `cret` are sorted by container name. /// /// **note:** `names` and `cret` may both (or either) be specified as /// `NULL`. /// /// **note:** `names` and `cret` must be freed by the caller. /// /// --- /// **version:** 1.0.0 pub fn list_active_containers( lxcpath: *const c_char, names: *mut *mut *mut c_char, cret: *mut *mut *mut lxc_container, ) -> *const c_int; /// Get a complete list of all containers for a given lxcpath. /// /// --- /// **Parameters** /// /// **lxcpath** Full `LXCPATH` path to consider. /// /// **names** *out* Dynamically-allocated array of container names. /// /// **cret** *out* Dynamically-allocated list of containers. /// /// --- /// **Returns** /// Number of containers found, or -1 on error. /// /// --- /// **note:** Some of the containers may not be "defined". /// /// **note:** Values returned in `cret` are sorted by container name. /// /// **note:** `names` and `cret` may both (or either) be specified as /// `NULL`. /// /// **note:** `names` and `cret` must be freed by the caller. /// /// --- /// **version:** 1.0.0 pub fn list_all_containers( lxcpath: *const c_char, names: *mut *mut *mut c_char, cret: *mut *mut *mut lxc_container, ) -> *const c_int; }