-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathfiles.c
3355 lines (2670 loc) · 99 KB
/
files.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>.
*
*
* files.c - this source file contains routines for manipulating
* files and directories for the nv-instaler.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/mman.h>
#include <sys/utsname.h>
#include <stdlib.h>
#include <limits.h>
#include <libgen.h>
#include <utime.h>
#include <time.h>
#include <sys/wait.h>
#include "nvidia-installer.h"
#include "user-interface.h"
#include "files.h"
#include "misc.h"
#include "precompiled.h"
#include "backup.h"
#include "kernel.h"
static void get_x_library_and_module_paths(Options *op);
/*
* remove_directory() - recursively delete a directory (`rm -rf`)
*/
int remove_directory(Options *op, const char *victim)
{
struct stat stat_buf;
DIR *dir;
struct dirent *ent;
int success = TRUE;
if (lstat(victim, &stat_buf) == -1) {
ui_error(op, "failure to open '%s'", victim);
return FALSE;
}
if (S_ISDIR(stat_buf.st_mode) == 0) {
ui_error(op, "%s is not a directory", victim);
return FALSE;
}
if ((dir = opendir(victim)) == NULL) {
ui_error(op, "Failure reading directory %s", victim);
return FALSE;
}
while (success && (ent = readdir(dir)) != NULL) {
char *filename;
int len;
if (((strcmp(ent->d_name, ".")) == 0) ||
((strcmp(ent->d_name, "..")) == 0)) continue;
len = strlen(victim) + strlen(ent->d_name) + 2;
filename = (char *) nvalloc(len);
snprintf(filename, len, "%s/%s", victim, ent->d_name);
if (lstat(filename, &stat_buf) == -1) {
ui_error(op, "failure to open '%s'", filename);
success = FALSE;
} else {
if (S_ISDIR(stat_buf.st_mode)) {
success = remove_directory(op, filename);
} else {
if (unlink(filename) != 0) {
ui_error(op, "Failure removing file %s (%s)",
filename, strerror(errno));
success = FALSE;
}
}
}
free(filename);
}
closedir(dir);
if (rmdir(victim) != 0) {
ui_error(op, "Failure removing directory %s (%s)",
victim, strerror(errno));
return FALSE;
}
return success;
}
/*
* touch_directory() - recursively touch all files (and directories)
* in the specified directory, bringing their access and modification
* times up to date.
*/
int touch_directory(Options *op, const char *victim)
{
struct stat stat_buf;
DIR *dir;
struct dirent *ent;
struct utimbuf time_buf;
int success = FALSE;
if (lstat(victim, &stat_buf) == -1) {
ui_error(op, "failure to open '%s'", victim);
return FALSE;
}
if (S_ISDIR(stat_buf.st_mode) == 0) {
ui_error(op, "%s is not a directory", victim);
return FALSE;
}
if ((dir = opendir(victim)) == NULL) {
ui_error(op, "Failure reading directory %s", victim);
return FALSE;
}
/* get the current time */
time_buf.actime = time(NULL);
time_buf.modtime = time_buf.actime;
/* loop over each entry in the directory */
while ((ent = readdir(dir)) != NULL) {
char *filename;
int entry_failed = FALSE;
if (((strcmp(ent->d_name, ".")) == 0) ||
((strcmp(ent->d_name, "..")) == 0)) continue;
filename = nvstrcat(victim, "/", ent->d_name, NULL);
/* stat the file to get the type */
if (lstat(filename, &stat_buf) == -1) {
ui_error(op, "failure to open '%s'", filename);
entry_failed = TRUE;
goto entry_done;
}
/* if it is a directory, call this recursively */
if (S_ISDIR(stat_buf.st_mode)) {
if (!touch_directory(op, filename)) {
entry_failed = TRUE;
goto entry_done;
}
}
/* finally, set the access and modification times */
if (utime(filename, &time_buf) != 0) {
ui_error(op, "Error setting modification time for %s", filename);
entry_failed = TRUE;
goto entry_done;
}
entry_done:
nvfree(filename);
if (entry_failed) {
goto done;
}
}
success = TRUE;
done:
if (closedir(dir) != 0) {
ui_error(op, "Error while closing directory %s.", victim);
success = FALSE;
}
return success;
}
/*
* copy_file() - copy the file specified by srcfile to dstfile, using
* mmap and memcpy. The destination file is created with the
* permissions specified by mode. Roughly based on code presented by
* Richard Stevens, in Advanced Programming in the Unix Environment,
* 12.9.
*/
int copy_file(Options *op, const char *srcfile,
const char *dstfile, mode_t mode)
{
int src_fd = -1, dst_fd = -1;
int success = FALSE;
struct stat stat_buf;
char *src, *dst;
if ((src_fd = open(srcfile, O_RDONLY)) == -1) {
ui_error (op, "Unable to open '%s' for copying (%s)",
srcfile, strerror (errno));
goto done;
}
if (stat(dstfile, &stat_buf) == 0) {
/* Unlink any existing destination file first, to ensure that the
destination file will be newly created, rather than overwriting
the contents of a file which may be in use by another program. */
if (unlink(dstfile) == -1 && errno != ENOENT) {
ui_error (op, "Unable to delete existing file '%s' (%s)",
dstfile, strerror (errno));
goto done;
}
}
if ((dst_fd = open(dstfile, O_RDWR | O_CREAT, mode)) == -1) {
ui_error (op, "Unable to create '%s' for copying (%s)",
dstfile, strerror (errno));
goto done;
}
if (fstat(src_fd, &stat_buf) == -1) {
ui_error (op, "Unable to determine size of '%s' (%s)",
srcfile, strerror (errno));
goto done;
}
if (stat_buf.st_size == 0) {
success = TRUE;
goto done;
}
if (lseek(dst_fd, stat_buf.st_size - 1, SEEK_SET) == -1) {
ui_error (op, "Unable to set file size for '%s' (%s)",
dstfile, strerror (errno));
goto done;
}
if (write(dst_fd, "", 1) != 1) {
ui_error (op, "Unable to write file size for '%s' (%s)",
dstfile, strerror (errno));
goto done;
}
if ((src = mmap(0, stat_buf.st_size, PROT_READ,
MAP_FILE | MAP_SHARED, src_fd, 0)) == (void *) -1) {
ui_error (op, "Unable to map source file '%s' for copying (%s)",
srcfile, strerror (errno));
goto done;
}
if ((dst = mmap(0, stat_buf.st_size, PROT_READ | PROT_WRITE,
MAP_FILE | MAP_SHARED, dst_fd, 0)) == (void *) -1) {
ui_error (op, "Unable to map destination file '%s' for copying (%s)",
dstfile, strerror (errno));
goto done;
}
memcpy (dst, src, stat_buf.st_size);
if (munmap (src, stat_buf.st_size) == -1) {
ui_error (op, "Unable to unmap source file '%s' after copying (%s)",
srcfile, strerror (errno));
goto done;
}
if (munmap (dst, stat_buf.st_size) == -1) {
ui_error (op, "Unable to unmap destination file '%s' after "
"copying (%s)", dstfile, strerror (errno));
goto done;
}
success = TRUE;
done:
if (success) {
/*
* the mode used to create dst_fd may have been affected by the
* user's umask; so explicitly set the mode again
*/
fchmod(dst_fd, mode);
}
if (src_fd != -1) {
close (src_fd);
}
if (dst_fd != -1) {
close (dst_fd);
}
return success;
}
/*
* write_temp_file() - write the given data to a temporary file,
* setting the file's permissions to those specified in perm. On
* success the name of the temporary file is returned; on error NULL
* is returned.
*/
char *write_temp_file(Options *op, const int len,
const void *data, mode_t perm)
{
unsigned char *dst = (void *) -1;
char *tmpfile = NULL;
int fd = -1;
int ret = FALSE;
/* create a temporary file */
tmpfile = nvstrcat(op->tmpdir, "/nv-tmp-XXXXXX", NULL);
fd = mkstemp(tmpfile);
if (fd == -1) {
ui_warn(op, "Unable to create temporary file (%s).",
strerror(errno));
goto done;
}
/* If a length of zero or a NULL data pointer was provided, skip writing
* to the file and just set the desired permissions. */
if (len && data) {
/* set the temporary file's size */
if (lseek(fd, len - 1, SEEK_SET) == -1) {
ui_warn(op, "Unable to set file size for temporary file (%s).",
strerror(errno));
goto done;
}
if (write(fd, "", 1) != 1) {
ui_warn(op, "Unable to write file size for temporary file (%s).",
strerror(errno));
goto done;
}
/* mmap the temporary file */
if ((dst = mmap(0, len, PROT_READ | PROT_WRITE,
MAP_FILE | MAP_SHARED, fd, 0)) == (void *) -1) {
ui_warn(op, "Unable to map temporary file (%s).", strerror(errno));
goto done;
}
/* copy the data out to the file */
memcpy(dst, data, len);
}
/* set the desired permissions on the file */
if (fchmod(fd, perm) == -1) {
ui_warn(op, "Unable to set permissions %04o on temporary "
"file (%s)", perm, strerror(errno));
goto done;
}
ret = TRUE;
done:
/* unmap the temporary file */
if (dst != (void *) -1) {
if (munmap(dst, len) == -1) {
ui_warn(op, "Unable to unmap temporary file (%s).",
strerror(errno));
}
}
/* close the temporary file */
if (fd != -1) close(fd);
if (ret) {
return tmpfile;
} else {
nvfree(tmpfile);
return NULL;
}
} /* write_temp_file() */
/*
* check_libGLX_indirect_target() - Helper function for
* check_libGLX_indirect_links.
*
* Checks to see if the installer should install (or overwrite) a
* libGLX_indirect.so.0 symlink.
*
* (path) should be the path to where the symlink would be installed.
*/
static int check_libGLX_indirect_target(Options *op, const char *path)
{
char *target = NULL;
char *base = NULL;
char *ext = NULL;
struct stat stat_buf;
int ret;
if (lstat(path, &stat_buf) != 0) {
// If the file doesn't exist, then we should create it.
return TRUE;
}
if (!S_ISLNK(stat_buf.st_mode)) {
// The file is not a symlink. Leave it alone.
return FALSE;
}
if (stat(path, &stat_buf) != 0) {
// If we can't resolve the link, then overwrite it.
return TRUE;
}
// Resolve the symlink.
target = get_resolved_symlink_target(op, path);
while (target != NULL) {
// Follow any more symlinks. The fact that the stat call above
// succeeded means that the link is valid.
char *nextTarget = NULL;
if (lstat(target, &stat_buf) != 0) {
free(target);
target = NULL;
break;
}
if (!S_ISLNK(stat_buf.st_mode)) {
break;
}
nextTarget = get_resolved_symlink_target(op, target);
free(target);
target = nextTarget;
}
if (target == NULL) {
// This should never happen.
ui_error(op, "Unable to resolve symbolic link \"%s\"\n", path);
return FALSE;
}
// Find the basename of the link target.
base = basename(target);
// Strip off the extension.
ext = strchr(base, '.');
if (ext != NULL) {
*ext = '\0';
}
// Finally, see if the resulting name is "libGLX_indirect". If it is, then
// we'll assume that the existing file is a dedicated indirect rendering
// library. Otherwise, we'll assume that it's a link to another vendor
// library.
if (strcmp(base, "libGLX_indirect") == 0) {
ret = FALSE;
} else {
ret = TRUE;
}
free(target);
return ret;
}
/*
* check_libGLX_indirect_links() - Finds the entries for the
* "libGLX_indirect.so.0" symlinks, and figures out whether to install them.
*/
static void check_libGLX_indirect_links(Options *op, Package *p)
{
int i;
if (op->install_libglx_indirect == NV_OPTIONAL_BOOL_TRUE) {
// The user specified that we should install the symlink.
return;
}
// Find the entries for libGLX_indirect.so.0, and decide whether or not to
// keep them.
for (i = 0; i < p->num_entries; i++) {
if (p->entries[i].dst != NULL && p->entries[i].type == FILE_TYPE_OPENGL_SYMLINK) {
if (strcmp(p->entries[i].name, "libGLX_indirect.so.0") == 0) {
int overwrite = FALSE;
if (op->install_libglx_indirect == NV_OPTIONAL_BOOL_DEFAULT) {
if (check_libGLX_indirect_target(op, p->entries[i].dst)) {
overwrite = TRUE;
}
}
if (!overwrite) {
invalidate_package_entry(&(p->entries[i]));
}
}
}
}
}
/*
* set_destinations() - given the Options and Package structures,
* assign the destination field in each Package entry, building from
* the OpenGL and XFree86 prefixes, the path relative to the prefix,
* and the filename. This assumes that the prefixes have already been
* assigned in the Options struct.
*/
int set_destinations(Options *op, Package *p)
{
char *name;
char *dir, *path;
const char *prefix;
int i;
if (!op->kernel_module_src_dir) {
op->kernel_module_src_dir = nvstrcat("nvidia-", p->version, NULL);
}
for (i = 0; i < p->num_entries; i++) {
/* If a file type's destination was overridden, use the override */
if (op->file_type_destination_overrides[p->entries[i].type] != NULL) {
p->entries[i].dst = nvstrcat(
op->file_type_destination_overrides[p->entries[i].type], "/",
p->entries[i].name, NULL);
collapse_multiple_slashes(p->entries[i].dst);
continue;
}
switch (p->entries[i].type) {
case FILE_TYPE_KERNEL_MODULE_SRC:
case FILE_TYPE_DKMS_CONF:
if (op->no_kernel_module_source) {
/* Don't install kernel module source files if requested. */
p->entries[i].dst = NULL;
continue;
}
prefix = op->kernel_module_src_prefix;
dir = op->kernel_module_src_dir;
path = p->entries[i].path;
break;
case FILE_TYPE_OPENGL_LIB:
case FILE_TYPE_OPENGL_SYMLINK:
case FILE_TYPE_GLVND_LIB:
case FILE_TYPE_GLVND_SYMLINK:
case FILE_TYPE_GLX_CLIENT_LIB:
case FILE_TYPE_GLX_CLIENT_SYMLINK:
case FILE_TYPE_EGL_CLIENT_LIB:
case FILE_TYPE_EGL_CLIENT_SYMLINK:
if (p->entries[i].compat_arch == FILE_COMPAT_ARCH_COMPAT32) {
prefix = op->compat32_prefix;
dir = op->compat32_libdir;
} else {
prefix = op->opengl_prefix;
dir = op->opengl_libdir;
}
path = "";
break;
case FILE_TYPE_WINE_LIB:
prefix = op->wine_prefix;
dir = op->wine_libdir;
path = "";
break;
case FILE_TYPE_VDPAU_LIB:
case FILE_TYPE_VDPAU_SYMLINK:
if (p->entries[i].compat_arch == FILE_COMPAT_ARCH_COMPAT32) {
prefix = op->compat32_prefix;
dir = op->compat32_libdir;
} else {
prefix = op->opengl_prefix;
dir = op->opengl_libdir;
}
path = p->entries[i].path;
break;
case FILE_TYPE_CUDA_LIB:
case FILE_TYPE_CUDA_SYMLINK:
case FILE_TYPE_OPENCL_LIB:
case FILE_TYPE_OPENCL_WRAPPER_LIB:
case FILE_TYPE_OPENCL_LIB_SYMLINK:
case FILE_TYPE_OPENCL_WRAPPER_SYMLINK:
if (p->entries[i].compat_arch == FILE_COMPAT_ARCH_COMPAT32) {
prefix = op->compat32_prefix;
dir = op->compat32_libdir;
} else {
prefix = op->opengl_prefix;
dir = op->opengl_libdir;
}
path = p->entries[i].path;
break;
case FILE_TYPE_CUDA_ICD:
prefix = DEFAULT_CUDA_ICD_PREFIX;
dir = DEFAULT_CUDA_ICD_DIR;
path = "";
break;
case FILE_TYPE_XMODULE_SHARED_LIB:
case FILE_TYPE_GLX_MODULE_SHARED_LIB:
case FILE_TYPE_GLX_MODULE_SYMLINK:
prefix = op->x_module_path;
dir = "";
path = p->entries[i].path;
break;
case FILE_TYPE_TLS_LIB:
if (p->entries[i].compat_arch == FILE_COMPAT_ARCH_COMPAT32) {
prefix = op->compat32_prefix;
dir = op->compat32_libdir;
} else {
prefix = op->opengl_prefix;
dir = op->opengl_libdir;
}
path = p->entries[i].path;
break;
case FILE_TYPE_UTILITY_LIB:
case FILE_TYPE_UTILITY_LIB_SYMLINK:
if (p->entries[i].compat_arch == FILE_COMPAT_ARCH_COMPAT32) {
prefix = op->compat32_prefix;
dir = op->compat32_libdir;
} else {
prefix = op->utility_prefix;
dir = op->utility_libdir;
}
path = "";
break;
case FILE_TYPE_GBM_BACKEND_LIB_SYMLINK:
p->entries[i].target = nvstrcat(op->utility_prefix, "/", op->utility_libdir, "/", p->entries[i].target, NULL);
/* fallthrough */
case FILE_TYPE_GBM_BACKEND_LIB:
prefix = op->opengl_prefix;
dir = op->gbm_backend_dir;
path = "";
break;
case FILE_TYPE_NVCUVID_LIB:
case FILE_TYPE_NVCUVID_LIB_SYMLINK:
if (p->entries[i].compat_arch == FILE_COMPAT_ARCH_COMPAT32) {
prefix = op->compat32_prefix;
dir = op->compat32_libdir;
} else {
prefix = op->opengl_prefix;
dir = op->opengl_libdir;
}
path = "";
break;
case FILE_TYPE_ENCODEAPI_LIB:
case FILE_TYPE_ENCODEAPI_LIB_SYMLINK:
if (p->entries[i].compat_arch == FILE_COMPAT_ARCH_COMPAT32) {
prefix = op->compat32_prefix;
dir = op->compat32_libdir;
} else {
prefix = op->opengl_prefix;
dir = op->opengl_libdir;
}
path = "";
break;
case FILE_TYPE_VGX_LIB:
case FILE_TYPE_VGX_LIB_SYMLINK:
prefix = op->opengl_prefix;
dir = op->opengl_libdir;
path = "";
break;
case FILE_TYPE_GRID_LIB:
case FILE_TYPE_GRID_LIB_SYMLINK:
case FILE_TYPE_FLEXERA_LIB:
case FILE_TYPE_FLEXERA_LIB_SYMLINK:
prefix = op->opengl_prefix;
dir = op->opengl_libdir;
path = p->entries[i].path;
break;
case FILE_TYPE_INSTALLER_BINARY:
prefix = op->utility_prefix;
dir = op->utility_bindir;
path = "";
break;
case FILE_TYPE_DOCUMENTATION:
prefix = op->documentation_prefix;
dir = op->documentation_docdir;
path = p->entries[i].path;
break;
case FILE_TYPE_MANPAGE:
case FILE_TYPE_NVIDIA_MODPROBE_MANPAGE:
prefix = op->documentation_prefix;
dir = op->documentation_mandir;
path = p->entries[i].path;
break;
case FILE_TYPE_APPLICATION_PROFILE:
prefix = op->application_profile_path;
dir = path = "";
break;
case FILE_TYPE_UTILITY_BINARY:
case FILE_TYPE_UTILITY_BIN_SYMLINK:
prefix = op->utility_prefix;
dir = op->utility_bindir;
path = "";
break;
case FILE_TYPE_DOT_DESKTOP:
prefix = op->xdg_data_dir;
dir = "applications";
path = "";
break;
case FILE_TYPE_ICON:
prefix = op->icon_dir;
dir = "";
path = p->entries[i].path;
break;
case FILE_TYPE_KERNEL_MODULE:
/*
* the kernel module dst field has already been
* initialized in add_kernel_module_to_package()
*/
continue;
case FILE_TYPE_MODULE_SIGNING_KEY:
prefix = op->module_signing_key_path;
dir = path = "";
break;
case FILE_TYPE_EXPLICIT_PATH:
case FILE_TYPE_NVIDIA_MODPROBE:
case FILE_TYPE_OPENGL_DATA:
prefix = p->entries[i].path;
dir = path = "";
break;
case FILE_TYPE_XORG_OUTPUTCLASS_CONFIG:
prefix = op->x_sysconfig_path;
dir = path = "";
break;
case FILE_TYPE_VULKAN_ICD_JSON:
/*
* Defined by the Vulkan Linux ICD loader specification.
*/
prefix = "/etc/vulkan/";
path = p->entries[i].path;
dir = "";
break;
case FILE_TYPE_VULKANSC_ICD_JSON:
/*
* Defined by the VulkanSC Linux ICD loader specification.
*/
prefix = "/etc/vulkansc/";
path = p->entries[i].path;
dir = "";
break;
case FILE_TYPE_GLVND_EGL_ICD_JSON:
// We'll set this path later in check_libglvnd_files. We have to
// wait until we figure out whether we're going to install our own
// build of the libglvnd libraries, which will determine where the
// JSON file goes.
p->entries[i].dst = NULL;
continue;
case FILE_TYPE_EGL_EXTERNAL_PLATFORM_JSON:
prefix = op->external_platform_json_path;
dir = path = "";
break;
case FILE_TYPE_INTERNAL_UTILITY_BINARY:
case FILE_TYPE_INTERNAL_UTILITY_LIB:
case FILE_TYPE_INTERNAL_UTILITY_DATA:
if (p->entries[i].compat_arch == FILE_COMPAT_ARCH_COMPAT32) {
// TODO: Avoid the chroot stuff below for this?
prefix = "/usr/lib/nvidia/32";
} else {
prefix = "/usr/lib/nvidia";
}
dir = path = "";
break;
case FILE_TYPE_FIRMWARE:
prefix = nvstrcat("/lib/firmware/nvidia/", p->version, "/", NULL);
path = p->entries[i].path;
dir = "";
break;
case FILE_TYPE_SYSTEMD_UNIT:
prefix = op->systemd_unit_prefix;
dir = path = "";
break;
case FILE_TYPE_SYSTEMD_UNIT_SYMLINK:
/*
* Construct the symlink target from the systemd unit prefix and
* symlink name.
*/
p->entries[i].target = nvstrcat(op->systemd_unit_prefix, "/", p->entries[i].name, NULL);
prefix = op->systemd_sysconf_prefix;
path = p->entries[i].path;
dir = "";
break;
case FILE_TYPE_SYSTEMD_SLEEP_SCRIPT:
prefix = op->systemd_sleep_prefix;
dir = path = "";
break;
default:
/*
* silently ignore anything that doesn't match; libraries
* of the wrong TLS class may fall in here, for example.
*/
p->entries[i].dst = NULL;
continue;
}
if ((prefix == NULL) || (dir == NULL) || (path == NULL)) {
p->entries[i].dst = NULL;
continue;
}
name = p->entries[i].name;
p->entries[i].dst = nvstrcat(prefix, "/", dir, "/", path, "/", name, NULL);
collapse_multiple_slashes(p->entries[i].dst);
#if defined(NV_X86_64)
if ((p->entries[i].compat_arch == FILE_COMPAT_ARCH_COMPAT32) &&
(op->compat32_chroot != NULL)) {
/*
* prepend an additional prefix; this is currently only
* used for Debian GNU/Linux on Linux/x86-64, but may see
* more use in the future.
*/
char *dst = p->entries[i].dst;
p->entries[i].dst = nvstrcat(op->compat32_chroot, dst, NULL);
nvfree(dst);
}
#endif /* NV_X86_64 */
}
return TRUE;
} /* set_destinations() */
/*
* get_prefixes() - if in expert mode, ask the user for the OpenGL and
* XFree86 installation prefix. The default prefixes are already set
* in parse_commandline().
*/
int get_prefixes (Options *op)
{
char *ret;
if (op->expert) {
ret = ui_get_input(op, op->x_prefix,
"X installation prefix (only under "
"rare circumstances should this be changed "
"from the default)");
if (ret && ret[0]) {
op->x_prefix = ret;
if (!confirm_path(op, op->x_prefix)) return FALSE;
}
}
remove_trailing_slashes(op->x_prefix);
ui_expert(op, "X installation prefix is: '%s'", op->x_prefix);
/*
* assign the X module and library paths; this must be done
* after the default prefixes/paths are assigned.
*/
if (op->x_files_packaged) {
get_x_library_and_module_paths(op);
}
if (op->expert) {
ret = ui_get_input(op, op->x_library_path,
"X library installation path (only under "
"rare circumstances should this be changed "
"from the default)");
if (ret && ret[0]) {
op->x_library_path = ret;
if (!confirm_path(op, op->x_library_path)) return FALSE;
}
}
remove_trailing_slashes(op->x_library_path);
ui_expert(op, "X library installation path is: '%s'", op->x_library_path);
if (op->expert) {
ret = ui_get_input(op, op->x_module_path,
"X module installation path (only under "
"rare circumstances should this be changed "
"from the default)");
if (ret && ret[0]) {
op->x_module_path = ret;
if (!confirm_path(op, op->x_module_path)) return FALSE;
}
}
remove_trailing_slashes(op->x_module_path);
ui_expert(op, "X module installation path is: '%s'", op->x_module_path);
if (op->expert) {
ret = ui_get_input(op, op->opengl_prefix,
"OpenGL installation prefix (only under "
"rare circumstances should this be changed "
"from the default)");
if (ret && ret[0]) {
op->opengl_prefix = ret;
if (!confirm_path(op, op->opengl_prefix)) return FALSE;
}
}
remove_trailing_slashes(op->opengl_prefix);
ui_expert(op, "OpenGL installation prefix is: '%s'", op->opengl_prefix);
if (op->expert) {
ret = ui_get_input(op, op->documentation_prefix,
"Documentation installation prefix (only under "
"rare circumstances should this be changed "
"from the default)");
if (ret && ret[0]) {
op->documentation_prefix = ret;
if (!confirm_path(op, op->documentation_prefix)) return FALSE;
}
}
remove_trailing_slashes(op->documentation_prefix);
ui_expert(op, "Documentation installation prefix is: '%s'", op->documentation_prefix);
if (op->expert) {
ret = ui_get_input(op, op->utility_prefix,
"Utility installation prefix (only under "
"rare circumstances should this be changed "
"from the default)");
if (ret && ret[0]) {
op->utility_prefix = ret;
if (!confirm_path(op, op->utility_prefix)) return FALSE;
}
}
remove_trailing_slashes(op->utility_prefix);
ui_expert(op, "Utility installation prefix is: '%s'", op->utility_prefix);
if (op->expert) {
op->no_kernel_module_source =
!ui_yes_no(op, !op->no_kernel_module_source,
"Do you want to install kernel module sources?");
}
if (!op->no_kernel_module_source) {
if (op->expert) {
ret = ui_get_input(op, op->kernel_module_src_prefix,
"Kernel module source installation prefix");
if (ret && ret[0]) {
op->kernel_module_src_prefix = ret;