-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathinstall-from-cwd.c
1491 lines (1165 loc) · 47.8 KB
/
install-from-cwd.c
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
/*
* nvidia-installer: A tool for installing NVIDIA software packages on
* Unix and Linux systems.
*
* Copyright (C) 2003 NVIDIA Corporation
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses>.
*
*
* install_from_cwd.c -
*/
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <stddef.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "nvidia-installer.h"
#include "user-interface.h"
#include "kernel.h"
#include "command-list.h"
#include "backup.h"
#include "files.h"
#include "misc.h"
#include "sanity.h"
#include "manifest.h"
/* local prototypes */
static Package *parse_manifest(Options *op);
static int install_kernel_modules(Options *op, Package *p);
static void free_package(Package *p);
static int assisted_module_signing(Options *op, Package *p);
static const KernelModuleInfo optional_modules[] = {
{
.module_name = "nvidia-uvm",
.optional_module_dependee = "CUDA",
.disable_option = "no-unified-memory",
.option_offset = offsetof(Options, install_uvm),
},
{
.module_name = "nvidia-drm",
.optional_module_dependee = "DRM-KMS",
.disable_option = "no-drm",
.option_offset = offsetof(Options, install_drm),
},
{
.module_name = "nvidia-peermem",
.optional_module_dependee = "GPUDirect RDMA p2p memory sharing",
.disable_option = "no-peermem",
.option_offset = offsetof(Options, install_peermem),
},
};
/*
* install_from_cwd() - perform an installation from the current
* working directory; we first ensure that we have a .manifest file in
* the cwd, and the files listed in the manifest exist and have
* correct checksums (to ensure the package hasn't been corrupted, not
* for anything security related).
*
* Second, make sure the user accepts the license.
*
* Then, optionally override the OpenGL and XFree86 installation
* prefixes.
*
* Determine the currently installed NVIDIA driver version (if any).
*
*/
int install_from_cwd(Options *op)
{
Package *p;
CommandList *c;
int ran_pre_install_hook = FALSE;
HookScriptStatus res;
static const char* module_only_text =
"kernel module for the ";
static const char* xconfig_success_text =
"Your X configuration file has been successfully updated. ";
static const char* edit_your_xorgconf_text =
" Please update your xorg.conf file as "
"appropriate; see the file /usr/share/doc/"
"NVIDIA_GLX-1.0/README.txt for details.";
/*
* validate the manifest file in the cwd, and process it, building
* a Package struct
*/
if ((p = parse_manifest(op)) == NULL) goto failed;
if (!op->x_files_packaged) {
edit_your_xorgconf_text = "";
}
ui_set_title(op, "%s (%s)", p->description, p->version);
/*
* warn the user if "legacy" GPUs are installed in this system
* and if no supported GPU is found, at all.
*/
check_for_nvidia_graphics_devices(op, p);
/* check that we are not running any X server */
if (!check_for_running_x(op)) goto failed;
/* run the distro pre unload hook */
res = run_distro_hook(op, "pre-unload");
if (res == HOOK_SCRIPT_FAIL) {
ui_error(op, "Pre-unload hook script failed");
goto failed;
}
/* make sure the kernel module is unloaded */
if (!check_for_unloaded_kernel_module(op)) goto failed;
ui_log(op, "Installing NVIDIA driver version %s.", p->version);
/*
* determine the current NVIDIA version (if any); ask the user if
* they really want to overwrite the existing installation
*/
if (!check_for_existing_driver(op, p)) goto exit_install;
/*
* check to see if an alternate method of installation is already installed
* or is available, but not installed; ask the user if they really want to
* install anyway despite the presence/availability of an alternate install.
*/
if (!check_for_alternate_install(op)) goto exit_install;
/* run the distro preinstall hook */
res = run_distro_hook(op, "pre-install");
if (res == HOOK_SCRIPT_FAIL) {
if (ui_multiple_choice(op, CONTINUE_ABORT_CHOICES,
NUM_CONTINUE_ABORT_CHOICES,
CONTINUE_CHOICE, /* Default choice */
"The distribution-provided pre-install "
"script failed! Are you sure you want "
"to continue?") == ABORT_CHOICE) {
goto failed;
}
} else if (res == HOOK_SCRIPT_SUCCESS) {
if (ui_multiple_choice(op, CONTINUE_ABORT_CHOICES,
NUM_CONTINUE_ABORT_CHOICES,
CONTINUE_CHOICE, /* Default choice */
"The distribution-provided pre-install script "
"completed successfully. If this is the first "
"time you have run the installer, this script "
"may have helped disable Nouveau, but a reboot "
"may be required first. "
"Would you like to continue, or would you "
"prefer to abort installation to reboot the "
"system?") == ABORT_CHOICE) {
goto exit_install;
}
ran_pre_install_hook = TRUE;
}
if (!op->no_kernel_modules) {
PrecompiledInfo *info = find_precompiled_kernel_interface(op, p);
if (info) {
free_precompiled(info);
/*
* make sure the required development tools are present on
* this system before trying to link the kernel interface.
*/
if (!check_precompiled_kernel_interface_tools(op)) return FALSE;
} else {
/*
* make sure the required development tools are present on
* this system before attempting to verify the compiler and
* trying to build a custom kernel interface.
*/
if (!check_development_tools(op, p)) return FALSE;
}
}
/* fail if the nouveau driver is currently in use */
if (!check_for_nouveau(op)) goto failed;
/* ask if we should install the optional kernel modules */
should_install_optional_modules(op, p, optional_modules,
ARRAY_LEN(optional_modules));
/* attempt to build the kernel modules for the target kernel */
if (!op->no_kernel_modules) {
if (!install_kernel_modules(op, p)) {
goto failed;
}
} else {
ui_warn(op, "You specified the '--no-kernel-modules' command line "
"option, nvidia-installer will not install any kernel "
"modules as part of this driver installation, and it will "
"not remove existing NVIDIA kernel modules not part of "
"an earlier NVIDIA driver installation. Please ensure "
"that NVIDIA kernel modules matching this driver version "
"are installed separately.");
}
/*
* if we are only installing the kernel modules, then remove
* everything else from the package; otherwise do some
* OpenGL-specific stuff
*/
if (op->kernel_modules_only) {
remove_non_kernel_module_files_from_package(p);
} else {
/* ask for the XFree86 and OpenGL installation prefixes. */
if (!get_prefixes(op)) goto failed;
/*
* if the package contains any .desktop files,
* process them (perform some search and replacing so
* that they reflect the correct installation path, etc)
* and add them to the package list (files to be installed).
*/
process_dot_desktop_files(op, p);
#if defined(NV_X86_64)
/*
* ask if we should install the 32bit compatibility files on
* this machine.
*/
should_install_compat32_files(op, p);
#endif /* NV_X86_64 */
}
if (op->no_opengl_files) {
remove_opengl_files_from_package(p);
} else {
check_for_vulkan_loader(op);
}
if (op->no_wine_files) {
remove_wine_files_from_package(p);
}
/*
* determine whether systemd files should be installed
*/
if (op->use_systemd != NV_OPTIONAL_BOOL_TRUE) {
remove_systemd_files_from_package(p);
}
/*
* Remove any kernel module source files that won't be installed.
*/
remove_non_installed_kernel_module_source_files_from_package(p);
/*
* now that we have the installation prefixes, build the
* destination for each file to be installed
*/
if (!set_destinations(op, p)) goto failed;
/*
* if we are installing OpenGL libraries, ensure that a symlink gets
* installed to /usr/lib/libGL.so.1. add_libgl_abi_symlink() sets its own
* destination, so it must be called after set_destinations().
*/
if (!op->kernel_modules_only && !op->no_opengl_files) {
add_libgl_abi_symlink(op, p);
}
if (!op->kernel_modules_only) {
/*
* uninstall the existing driver; this needs to be done before
* building the command list.
*
* XXX if we uninstall now, then build the command list, and
* then ask the user if they really want to execute the
* command list, if the user decides not to execute the
* command list, they'll be left with no driver installed.
*/
if (!run_existing_uninstaller(op)) goto failed;
/* initialize the backup log */
if (!init_backup(op, p)) goto failed;
}
if (!op->no_kernel_modules) {
/* Import the modules into DKMS, if requested */
dkms_register_module(op, p, get_kernel_name(op));
}
if (!check_libglvnd_files(op, p)) {
goto failed;
}
/* build a list of operations to execute to do the install */
if ((c = build_command_list(op, p)) == NULL) goto failed;
/* call the ui to get approval for the list of commands */
if (!ui_approve_command_list(op, c, "%s", p->description)) {
goto exit_install;
}
/* execute the command list */
if (!do_install(op, p, c)) goto failed;
/*
* Leave nvidia-drm loaded in case an X server with OutputClass-based driver
* matching is being used.
*/
if (!op->no_kernel_modules) {
if (package_includes_kernel_module(p, "nvidia-drm")) {
if (!load_kernel_module(op, "nvidia-drm")) {
goto failed;
}
}
if (package_includes_kernel_module(p, "nvidia-vgpu-vfio")) {
if (!load_kernel_module(op, "nvidia-vgpu-vfio")) {
goto failed;
}
}
}
/* run the distro postinstall script */
run_distro_hook(op, "post-install");
/*
* check that everything is installed properly (post-install
* sanity check)
*/
check_installed_files_from_package(op, p);
/* done */
if (!op->kernel_modules_only) {
module_only_text = "";
}
if (op->kernel_modules_only || op->no_nvidia_xconfig_question) {
xconfig_success_text = "";
edit_your_xorgconf_text = "";
} else {
int ret;
/* ask the user if they would like to run nvidia-xconfig */
const char *msg = "Would you like to run the nvidia-xconfig utility "
"to automatically update your X configuration file "
"so that the NVIDIA X driver will be used when you "
"restart X? Any pre-existing X configuration "
"file will be backed up.";
ret = run_nvidia_xconfig(op, FALSE, msg, op->run_nvidia_xconfig);
if (ret) {
edit_your_xorgconf_text = "";
} else {
xconfig_success_text = "";
}
}
ui_message(op,
"%sInstallation of the %s%s (version: %s) is now complete.%s",
xconfig_success_text, module_only_text,
p->description, p->version,
edit_your_xorgconf_text);
free_package(p);
return TRUE;
failed:
/*
* something bad happened during installation; print an error
* message and return FALSE
*/
if (op->logging) {
ui_error(op, "Installation has failed. Please see the file '%s' "
"for details. You may find suggestions on fixing "
"installation problems in the README available on the "
"Linux driver download page at www.nvidia.com.",
op->log_file_name);
} else {
ui_error(op, "Installation has failed. You may find suggestions "
"on fixing installation problems in the README available "
"on the Linux driver download page at www.nvidia.com.");
}
if (ran_pre_install_hook)
run_distro_hook(op, "failed-install");
/* fall through into exit_install... */
exit_install:
/*
* we are exiting installation; this can happen for reasons that
* do not merit the error message (e.g., the user declined the
* license agreement)
*/
free_package(p);
return FALSE;
} /* install_from_cwd() */
/*
* Attempt to build and install the appropriate kernel modules for the
* running kernel; we first check if prebuilt kernel interfaces exist.
* If yes, we try to link those into the final kernel module, else we
* try to build from source.
*
* If we succeed in building the kernel modules, we attempt to load
* them into the host kernel and add them to the list of files to
* install if the load attempt succeeds.
*/
static int install_kernel_modules(Options *op, Package *p)
{
PrecompiledInfo *precompiled_info;
process_dkms_conf(op,p);
/* determine where to install the kernel module */
if (!determine_kernel_module_installation_path(op)) return FALSE;
/* check '/proc/sys/kernel/modprobe' */
if (!check_proc_modprobe_path(op)) return FALSE;
/*
* do nvchooser-style logic to decide if we have a prebuilt kernel
* module for their kernel
*
* XXX One could make the argument that we should not actually do
* the building/linking now, but just add this to the list of
* operations and do it when we execute the operation list. I
* think it's better to make sure we have a kernel module early on
* -- a common problem for users will be not having a prebuilt
* kernel interface for their kernel, and not having the kernel
* headers installed, so it's better to catch that earlier on.
*/
if ((precompiled_info = find_precompiled_kernel_interface(op, p))) {
int i, precompiled_success = TRUE;
/*
* we have a prebuilt kernel interface package, so now link the
* kernel interface files to produce the kernel module.
*
* XXX if linking fails, maybe we should fall through and
* attempt to build the kernel module? No, if linking fails,
* then there is something pretty seriously wrong... better to
* abort.
*/
for (i = 0; i < precompiled_info->num_files; i++) {
if (!unpack_kernel_modules(op, p, p->kernel_module_build_directory,
&(precompiled_info->files[i]))) {
precompiled_success = FALSE;
break;
}
}
free_precompiled(precompiled_info);
if (!precompiled_success) {
return FALSE;
}
} else {
/*
* we do not have a prebuilt kernel interface; thus we'll need
* to compile the kernel interface, so determine where the
* kernel source files are.
*/
if (!determine_kernel_source_path(op, p)) return FALSE;
/* and now, build the kernel interface */
if (!build_kernel_modules(op, p)) return FALSE;
}
/* Optionally sign the kernel module */
if (!assisted_module_signing(op, p)) return FALSE;
/*
* if we got this far, we have a complete kernel module; test it
* to be sure it's OK
*/
if (!test_kernel_modules(op, p)) return FALSE;
/* add the kernel modules to the list of things to install */
add_kernel_modules_to_package(op, p);
return TRUE;
}
/*
* add_this_kernel() - build a precompiled kernel interface for the
* running kernel, and repackage the .run file to include the new
* precompiled kernel interface.
*/
int add_this_kernel(Options *op)
{
Package *p;
PrecompiledFileInfo *fileInfos;
/* parse the manifest */
if ((p = parse_manifest(op)) == NULL) goto failed;
/* make sure we have the development tools */
if (!check_development_tools(op, p)) goto failed;
/* find the kernel header files */
if (!determine_kernel_source_path(op, p)) goto failed;
/* build the precompiled files */
if (p->num_kernel_modules != build_kernel_interfaces(op, p, &fileInfos))
goto failed;
/* pack the precompiled files */
if (!pack_precompiled_files(op, p, p->num_kernel_modules, fileInfos))
goto failed;
free_package(p);
return TRUE;
failed:
ui_error(op, "Unable to add a precompiled kernel interface for the "
"running kernel.");
free_package(p);
return FALSE;
} /* add_this_kernel() */
/*
* Returns TRUE if the given module has a separate interface, FALSE otherwise.
*/
static int has_separate_interface_file(char *name) {
int i;
static const char* no_interface_modules[] = {
"nvidia-vgpu-vfio",
"nvidia-uvm",
"nvidia-drm",
"nvidia-peermem",
};
for (i = 0; i < ARRAY_LEN(no_interface_modules); i++) {
if (strcmp(no_interface_modules[i],name) == 0) {
return FALSE;
}
}
return TRUE;
};
/*
* Populate the module info records for optional records with information
* that can be used in e.g. error messages.
*/
static void populate_optional_module_info(KernelModuleInfo *module)
{
int i;
for (i = 0; i < ARRAY_LEN(optional_modules); i++) {
if (strcmp(optional_modules[i].module_name, module->module_name) == 0) {
module->is_optional = TRUE;
module->optional_module_dependee =
optional_modules[i].optional_module_dependee;
module->disable_option = optional_modules[i].disable_option;
module->option_offset = optional_modules[i].option_offset;
return;
}
}
}
/*
* Return a string with 'suffix' appended to the original source string, after
* replacing "nvidia" with "nv" at the beginning of the original source string.
*/
static char *nvidia_to_nv(const char *name, const char *suffix) {
if (strncmp("nvidia", name, strlen("nvidia")) != 0) {
return NULL;
}
return nvstrcat("nv", name + strlen("nvidia"), suffix, NULL);
}
/*
* Iterate over the list of kernel modules from the manifest file; generate
* and store module information records for each module in the Package.
*/
static int parse_kernel_modules_list(Package *p, char *list) {
char *name;
p->num_kernel_modules = 0; /* in case this gets called more than once */
for (name = strtok(list, " "); name; name = strtok(NULL, " ")) {
KernelModuleInfo *module;
p->kernel_modules = nvrealloc(p->kernel_modules,
(p->num_kernel_modules + 1) *
sizeof(p->kernel_modules[0]));
module = p->kernel_modules + p->num_kernel_modules;
memset(module, 0, sizeof(*module));
module->module_name = nvstrdup(name);
module->module_filename = nvstrcat(name, ".ko", NULL);
module->has_separate_interface_file = has_separate_interface_file(name);
if (module->has_separate_interface_file) {
char *core_binary = nvidia_to_nv(name, "-kernel.o_binary");
module->interface_filename = nvidia_to_nv(name, "-linux.o");
module->core_object_name = nvstrcat(name, "/", core_binary, NULL);
nvfree(core_binary);
}
populate_optional_module_info(module);
p->num_kernel_modules++;
}
return p->num_kernel_modules;
}
/*
* parse_manifest() - open and read the .manifest file in the current
* directory.
*
* The first nine lines of the .manifest file are:
*
* - a description string
* - a version string
* - the kernel module file name
* - the kernel interface file name
* - the kernel module name (what `rmmod` and `modprobe` should use)
* - a whitespace-separated list of module names that should be
* removed before installing a new kernel module
* - a whitespace-separated list of kernel module filenames that
* should be uninstalled before installing a new kernel module
* - kernel module build directory
* - directory containing precompiled kernel interfaces
*
* The rest of the manifest file is file entries. A file entry is a
* whitespace-separated list containing:
*
* - a filename (relative to the cwd)
* - an octal value describing the permissions
* - a flag describing the file type
* - certain file types have an architecture
* - certain file types have a second flag
* - certain file types will have a path
* - file types which inherit their paths will have a path depth
* - symbolic links will name the target of the link
*/
static Package *parse_manifest (Options *op)
{
char *buf, *c, *tmpstr;
int line;
int fd, ret, len = 0;
struct stat stat_buf;
Package *p;
char *manifest = MAP_FAILED, *ptr;
int opengl_files_packaged = FALSE;
p = (Package *) nvalloc(sizeof (Package));
/* open the manifest file */
if ((fd = open(".manifest", O_RDONLY)) == -1) {
ui_error(op, "No package found for installation. Please run "
"this utility with the '--help' option for usage "
"information.");
goto fail;
}
if (fstat(fd, &stat_buf) == -1) goto cannot_open;
len = stat_buf.st_size;
manifest = mmap(0, len, PROT_READ, MAP_FILE|MAP_SHARED, fd, 0);
if (manifest == MAP_FAILED) goto cannot_open;
/* the first line is the description */
line = 1;
p->description = get_next_line(manifest, &ptr, manifest, len);
if (!p->description) goto invalid_manifest_file;
/* the second line is the version */
line++;
p->version = get_next_line(ptr, &ptr, manifest, len);
if (!p->version) goto invalid_manifest_file;
/* Ignore the third line */
line++;
nvfree(get_next_line(ptr, &ptr, manifest, len));
/* the fourth line is the list of kernel modules. */
line++;
tmpstr = get_next_line(ptr, &ptr, manifest, len);
if (parse_kernel_modules_list(p, tmpstr) == 0) {
goto invalid_manifest_file;
}
nvfree(tmpstr);
/*
* set the default value of excluded_kernel_modules to an empty, heap
* allocated string so that it can be freed and won't prematurely end
* an nvstrcat()ed string when unset.
*/
p->excluded_kernel_modules = nvstrdup("");
/*
* ignore the fifth through eigth lines
*/
line++;
nvfree(get_next_line(ptr, &ptr, manifest, len));
line++;
nvfree(get_next_line(ptr, &ptr, manifest, len));
line++;
nvfree(get_next_line(ptr, &ptr, manifest, len));
line++;
nvfree(get_next_line(ptr, &ptr, manifest, len));
/*
* allow the kernel module build directory to be overridden from the command
* line
*/
if (op->kernel_module_build_directory_override) {
p->kernel_module_build_directory =
op->kernel_module_build_directory_override;
op->kernel_module_build_directory_override = NULL;
} else {
struct module_type_info types;
int num_types;
num_types = valid_kernel_module_types(op, &types);
if (num_types > 0) {
int selection;
if (num_types == 1) {
selection = 0;
} else {
selection = ui_multiple_choice(op, types.licenses, num_types,
types.default_entry,
"Multiple kernel module types are available for this "
"system. Which would you like to use?"
);
}
p->kernel_module_build_directory = nvstrdup(types.dirs[selection]);
} else {
p->kernel_module_build_directory = nvstrdup("kernel");
}
}
remove_trailing_slashes(p->kernel_module_build_directory);
/* the rest of the file is file entries */
line++;
for (; (buf = get_next_line(ptr, &ptr, manifest, len)); line++) {
char *flag = NULL;
PackageEntry entry;
int entry_success = FALSE;
if (buf[0] == '\0') {
free(buf);
break;
}
/* initialize the new entry */
memset(&entry, 0, sizeof(PackageEntry));
/* read the file name and permissions */
c = buf;
entry.file = read_next_word(buf, &c);
if (!entry.file) goto entry_done;
tmpstr = read_next_word(c, &c);
if (!tmpstr) goto entry_done;
/* translate the mode string into an octal mode */
ret = mode_string_to_mode(op, tmpstr, &entry.mode);
free(tmpstr);
if (!ret) goto entry_done;
/* every file has a type field */
entry.type = FILE_TYPE_NONE;
flag = read_next_word(c, &c);
if (!flag) goto entry_done;
entry.type = parse_manifest_file_type(flag, &entry.caps);
if (entry.type == FILE_TYPE_NONE) {
goto entry_done;
}
/* Track whether certain file types were packaged */
switch (entry.type) {
case FILE_TYPE_XMODULE_SHARED_LIB:
op->x_files_packaged = TRUE;
break;
case FILE_TYPE_VULKAN_ICD_JSON:
op->vulkan_icd_json_packaged = TRUE;
break;
case FILE_TYPE_VULKANSC_ICD_JSON:
op->vulkansc_icd_json_packaged = TRUE;
break;
default: break;
}
/* set opengl_files_packaged if any OpenGL files were packaged */
if (entry.caps.is_opengl) {
opengl_files_packaged = TRUE;
}
/* some libs/symlinks have an arch field */
entry.compat_arch = FILE_COMPAT_ARCH_NONE;
if (entry.caps.has_arch) {
nvfree(flag);
flag = read_next_word(c, &c);
if (!flag) goto entry_done;
if (strcmp(flag, "COMPAT32") == 0)
entry.compat_arch = FILE_COMPAT_ARCH_COMPAT32;
else if (strcmp(flag, "NATIVE") == 0)
entry.compat_arch = FILE_COMPAT_ARCH_NATIVE;
else {
goto entry_done;
}
}
/* if compat32 files are packaged, set compat32_files_packaged */
if (entry.compat_arch == FILE_COMPAT_ARCH_COMPAT32) {
op->compat32_files_packaged = TRUE;
}
/* some file types have a path field, or inherit their paths */
if (entry.caps.has_path) {
entry.path = read_next_word(c, &c);
if (!entry.path) goto invalid_manifest_file;
} else if (entry.caps.inherit_path) {
int i;
char *path, *depth, *slash;
const char * const depth_marker = "INHERIT_PATH_DEPTH:";
depth = read_next_word(c, &c);
if (!depth ||
strncmp(depth, depth_marker, strlen(depth_marker)) != 0) {
goto invalid_manifest_file;
}
entry.inherit_path_depth = atoi(depth + strlen(depth_marker));
nvfree(depth);
/* Remove the file component from the packaged filename */
path = entry.path = nvstrdup(entry.file);
slash = strrchr(path, '/');
if (slash == NULL) {
goto invalid_manifest_file;
}
slash[1] = '\0';
/* Strip leading directory components from the path */
for (i = 0; i < entry.inherit_path_depth; i++) {
slash = strchr(entry.path, '/');
if (slash == NULL) {
goto invalid_manifest_file;
}
entry.path = slash + 1;
}
entry.path = nvstrdup(entry.path);
nvfree(path);
} else {
entry.path = NULL;
}
/* symlinks have a target */
if (entry.caps.is_symlink) {
entry.target = read_next_word(c, &c);
if (!entry.target) goto invalid_manifest_file;
} else {
entry.target = NULL;
}
/*
* as a convenience for later, set the 'name' pointer to
* the basename contained in 'file' (ie the portion of
* 'file' without any leading directory components
*/
entry.name = strrchr(entry.file, '/');
if (entry.name) entry.name++;
if (!entry.name) entry.name = entry.file;
add_package_entry(p,
entry.file,
entry.path,
entry.name,
entry.target,